-
Notifications
You must be signed in to change notification settings - Fork 38.6k
http: add evhttp_connection_set_closecb to avoid g_requests hang #27909
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
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.
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 is the culprit of what you're observing.
reqbecomes a dangling pointer as soon as a request is completed. In most cases (which is why we typically need > 1 number of iterations), this just means thatg_requests.erase(req)removes 0 elements because it points to a non-existing request, but sometimes (and actually quite frequently as addresses seem to be reused quite aggressively) this will point to an unrelated request which has already been added intog_requests, erasing it unintentionally.The underlying issue is that an
evhttp_connectionand anevhttp_requestsimply have different lifecycles, with connections living longer than requests. It seems that passingreqas an argument toevhttp_connection_set_closecbis a fundamentally unsafe thing to do if we can't guarantee thatreqhasn't been completed by the timeclosecbis called (which in the happy path, we always expect it to be).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.
nice catch!
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.
What about this:
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'm not sure this will be 100% robust when we have multiple requests in a connection, I think this can still lead to usage of stale pointers? But as we're closing the connection anyway, it may not be an issue.
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 the most sensible approach is to instead of track requests, keep a per-connection request counter. It's a pretty straightforward approach with a
std::unordered_map<const evhttp_connection*, size_t>, but I've added aRequestTrackerhelper class wrapping around that to make that a bit more robust. What do you think?stickies-v@953c691
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've opened #28551 with this approach to try and get it in before v26.