-
Notifications
You must be signed in to change notification settings - Fork 186
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
📸 Preview service has generated an image. |
📸 Preview service has generated an image. |
📸 Preview service has generated an image. |
iainsproat
commented
Feb 4, 2025
dbStream.destroy.bind(dbStream) | ||
res.on('close', () => { | ||
dbStream.end() | ||
dbStream.destroy() |
There was a problem hiding this comment.
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
requested review from
gjedlicska,
adamhathcock,
fabis94 and
alemagio
February 4, 2025 08:51
gjedlicska
approved these changes
Feb 4, 2025
iainsproat
added a commit
that referenced
this pull request
Feb 4, 2025
6 tasks
iainsproat
added a commit
that referenced
this pull request
Feb 4, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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':
Changes:
Listen to
close
events on the Response, not the Request..bind(dbStream)
did not work.Adds a further test for scenarios which caused the previous solution (fix(server/objects): solves database connection resource leak when client connections are prematurely closed #3889) to fail. This is intended to prevent regression.
The CSV file is a partial data dump of the objects for the Speckle onboarding model, reduced to the minimum failing example.
Most of this PR removes the previous, failing, 'fix'.
To-do before merge:
Screenshots:
Validation of changes:
Checklist:
References