-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Preserve thread context when calling getNextPart()
#109519
Preserve thread context when calling getNextPart()
#109519
Conversation
The listener supplied to `getNextPart()` may be completed in a non-default thread context, and this trips assertions about thread context pollution in the transport layer, so this commit adds the missing protection against that. Also the listener supplied to `getNextPart()` may be completed immediately on the transport thread, which could lead to a stack overflow, so this commit adds another `execute()` call to unconditionally fork a fresh task. Relates elastic#104851
Pinging @elastic/es-distributed (Team:Distributed) |
Which assertion is this? Have you seen such a test failure that can be linked to this PR? |
Any of the various existing calls to |
Also FWIW this is the same as what we do in |
}), finishingWriteBodyPart::getNextPart); | ||
ActionListener.run( | ||
new ContextPreservingActionListener<>( | ||
threadContext.newRestorableContext(false), |
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.
If the response has multiple continuations, it seems to me that we are technically restoring the threadContext from the previous iteration instead of the threadContext when we send the first part? But maybe it is effectively the same since (1) the capture and restore are chained and (2) there is nothing in writeAndFlush
could change the threadContext?
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.
Right, but we're in the Netty event loop here so we are indeed not changing the thread context (which is why we call assertDefaultThreadContext
to check that)
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.
assertDefaultThreadContext
does not check response header. But I see what you mean.
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.
LGTM
With the changes in elastic#109519 we now do one more async step while serving the response, so we need to acquire another ref to track the new step. Relates elastic#109866 Relates elastic#110118 Relates elastic#110175 Relates elastic#110249
The listener supplied to
getNextPart()
may be completed in anon-default thread context, and this trips assertions about thread
context pollution in the transport layer, so this commit adds the
missing protection against that.
Also the listener supplied to
getNextPart()
may be completedimmediately on the transport thread, which could lead to a stack
overflow, so this commit adds another
execute()
call tounconditionally fork a fresh task.
Relates #104851