Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server/database streams): remove event listener on batch completion #3938

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

iainsproat
Copy link
Contributor

@iainsproat iainsproat commented Feb 5, 2025

Description & motivation

In response to observed log line:

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [ServerResponse]. Use emitter.setMaxListeners() to increase limit

This might explain the remaining database connection leaks. We're batching the database streams and each batch adds a listener to the response. Large models with a large number of batches could exceed the number of listeners.
This max value will limit the number of listeners, meaning that subsequent batches cannot add listeners and will not be closed if the client connection is subsequently closed.

Changes:

  • refactors anonymous event handler to a named event handler
  • removes the named event handler from the response event listeners when the database stream is closed

To-do before merge:

Screenshots:

Validation of changes:

Checklist:

  • My pull request follows the guidelines in the Contributing guide?
  • My pull request does not duplicate any other open Pull Requests for the same update/change?
  • My commits are related to the pull request and do not amend unrelated code or documentation.
  • My code follows a similar style to existing code.
  • I have added appropriate tests.
  • I have updated or added relevant documentation.

References

Copy link
Contributor

github-actions bot commented Feb 5, 2025

📸 Preview service has generated an image.

@iainsproat iainsproat marked this pull request as ready for review February 5, 2025 15:05
@gjedlicska
Copy link
Contributor

so far, that warning was not causing issues in my testings with the EventBus, but the change is legit, so lets see.

@iainsproat iainsproat merged commit 947f8fd into main Feb 5, 2025
28 of 30 checks passed
@iainsproat iainsproat deleted the iain/release-event-listeners branch February 5, 2025 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants