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/diffdownload): fix the bug where client connection close events were not propogated to the database stream connection #3921

Merged
merged 11 commits into from
Feb 4, 2025

Conversation

iainsproat
Copy link
Contributor

@iainsproat iainsproat commented Jan 31, 2025

Description & motivation

This is a more complete fix which #3889 aimed to resolve, but which introduced additional bugs on some models.

This PR fixes a long existing bug with prematurely closed streaming connections. Prior to this PR, for the /api/getobjects/* REST endpoint, if the client prematurely closed a connection to the server it was not propogated to the database connection. This resulted in the database connection never being closed, and inevitably saturation for the server and the inability to serve further traffic (reffectively a Denial of Service until the server is restarted).

The root cause of the bug is an issue with Node.js stream.pipeline implementation, described in the documentation as so:

stream.pipeline() leaves dangling event listeners on the streams after the callback has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors.

Previously we had an improper implementation of the workaround for the above. This PR fixes that implementation.

The changes which are relevant are best reviewed by diffing against the changes prior to the previous 'fix':

git diff fc634ebfe5deec336f7d6c84e584ae77f24a65c1 -- packages/server/modules/core/rest/diffDownload.ts

Changes:

To-do before merge:

  • test should have minimally failing example

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

@iainsproat iainsproat changed the title WIP: trying to catch a bug in objects streaming fix(server/diffdownload): fix the bug where client connection close events were not propogated to the database stream connection Jan 31, 2025
Copy link
Contributor

📸 Preview service has generated an image.

Copy link
Contributor

📸 Preview service has generated an image.

Copy link
Contributor

📸 Preview service has generated an image.

dbStream.destroy.bind(dbStream)
res.on('close', () => {
dbStream.end()
dbStream.destroy()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the fix, so simple in the end.
Listen to events on the response, not the request. And .bind wasn't required.

@iainsproat iainsproat marked this pull request as ready for review February 4, 2025 08:51
@gjedlicska gjedlicska merged commit 55315fe into main Feb 4, 2025
28 of 30 checks passed
@gjedlicska gjedlicska deleted the iain/zombie-streaming-db-connections-part-2 branch February 4, 2025 10:09
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