Fix race in HTTP response shutdown handling#105306
Merged
DaveCTurner merged 3 commits intoelastic:mainfrom Feb 9, 2024
Merged
Conversation
Similar to elastic#97301, the fix in elastic#105293 was still not quite correct: we could in principle shut down the transport after checking `isOpen()` but before sending the message. Applying the same fix as for the transport layer here.
Collaborator
|
Hi @DaveCTurner, I've created a changelog YAML for you. |
Collaborator
|
Pinging @elastic/es-distributed (Team:Distributed) |
ywangd
approved these changes
Feb 9, 2024
Comment on lines
+39
to
41
| if (channel.eventLoop().isShutdown()) { | ||
| wrapped.onFailure(new TransportException("Cannot send HTTP response, event loop is shutting down.")); | ||
| } |
Member
There was a problem hiding this comment.
If the event loop stops after this check, I assume we can rely on Netty to release the response?
Member
Author
There was a problem hiding this comment.
Yeah shutting down the event loop involves draining the executor's queue. If we get here and the event loop isn't shut down then we know the work was enqueued and thus will run.
DaveCTurner
added a commit
to DaveCTurner/elasticsearch
that referenced
this pull request
Feb 9, 2024
Similar to elastic#97301, the fix in elastic#105293 was still not quite correct: we could in principle shut down the transport after checking `isOpen()` but before sending the message. Applying the same fix as for the transport layer here.
Collaborator
💚 Backport successful
|
elasticsearchmachine
pushed a commit
that referenced
this pull request
Feb 9, 2024
DaveCTurner
added a commit
to DaveCTurner/elasticsearch
that referenced
this pull request
Feb 14, 2024
We could still be manipulating a network message when the event loop shuts down, causing us to close the message while it's still in use. This is at best going to be a little surprising to the caller, and at worst could be an outright use-after-free bug. This commit moves the double-check for a leaked promise to happen strictly after the event loop has fully terminated, so that we can be sure we've finished using it by this point. Relates elastic#105306, elastic#97301
elasticsearchmachine
pushed a commit
that referenced
this pull request
Feb 15, 2024
We could still be manipulating a network message when the event loop shuts down, causing us to close the message while it's still in use. This is at best going to be a little surprising to the caller, and at worst could be an outright use-after-free bug. This commit moves the double-check for a leaked promise to happen strictly after the event loop has fully terminated, so that we can be sure we've finished using it by this point. Relates #105306, #97301
DaveCTurner
added a commit
to DaveCTurner/elasticsearch
that referenced
this pull request
Feb 15, 2024
We could still be manipulating a network message when the event loop shuts down, causing us to close the message while it's still in use. This is at best going to be a little surprising to the caller, and at worst could be an outright use-after-free bug. This commit moves the double-check for a leaked promise to happen strictly after the event loop has fully terminated, so that we can be sure we've finished using it by this point. Relates elastic#105306, elastic#97301
elasticsearchmachine
pushed a commit
that referenced
this pull request
Feb 15, 2024
We could still be manipulating a network message when the event loop shuts down, causing us to close the message while it's still in use. This is at best going to be a little surprising to the caller, and at worst could be an outright use-after-free bug. This commit moves the double-check for a leaked promise to happen strictly after the event loop has fully terminated, so that we can be sure we've finished using it by this point. Relates #105306, #97301
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
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.
Similar to #97301, the fix in #105293 was still not quite correct: we
could in principle shut down the transport after checking
isOpen()butbefore sending the message. Applying the same fix as for the transport
layer here.