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.
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 cursor thread leak from closing unconsumed iterators #917
Fix cursor thread leak from closing unconsumed iterators #917
Changes from all commits
2ef0368
ae0765c
ab91b81
95a3e11
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Late suggestion: why not move this code above and get rid of the scope guard completely?
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.
See below for why. The asserts are not why we need the scope_guard (they should be expected to terminate the program, so the socket would be closed in any case).
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.
Here too we could probably move this code and eliminate the scope_guard. The asserts can happen after the wrapping into the shared_ptr.
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.
I think we need the scope_guard regardless, because dynamic allocation can always throw, and we need to close the socket in that case.
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.
(There are actually 2 dynamic allocations happening here: one explicit, which is our
operator new
call, and the other implicit, which isshared_ptr
allocating its shared refcount structure on the heap.make_shared()
combines these into a single allocation, but we can't use it because it doesn't support custom deleters.)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.
But then why remove the scope guard in the other situations? You could have kept it for the same reason.
Anyway, I don't think we should worry about cleanup in the case that
new()
fails - in that case the server would stop execution anyway.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.
You're right that in general we don't try to recover from exceptions on the server (unless they're from a misbehaving or crashed client), but the iterator code is all client-side at least conceptually (i.e., it consumes a "cursor socket" sent over the session socket by the server). We don't control the exception handling policy in a client application (e.g., the client might try to recover from a
std::bad_alloc
exception thrown by thestream_socket_ptr
allocation by freeing some memory that they own). That's why exception safety is important to get right on the client, while it can be treated as a mostly theoretical concern on the server (but I still treat non-exception-safety as a bug there as well).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.
Not totally sure which "other situations" you're referring to, but the reason I removed
scope_guard
in the consumers ofstream_socket_ptr
is that theshared_ptr
destructor now closes the socket if an exception is thrown in one of the consumers, so exception safety no longer requires ascope_guard
there. The key difference is that theshared_ptr
has already been successfully constructed at that point, so it now owns the socket and its destructor is responsible for closing the socket.