-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Schedule commands in current thread context #54187
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
Schedule commands in current thread context #54187
Conversation
Pinging @elastic/es-core-infra (:Core/Infra/Core) |
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.
+1
It has been a while since I looked at this! The reason I never made this change when I worked on this before was that I thought that some calls to schedule
intentionally didn't keep the thread context. I wonder if it'd be best to explicitly throw away the context in the places where we don't want to preserve it. It might be as simple as adding a boolean to schedule
or something like that. I hate to change the signature but that'd force you to think about whether or not you want to preserve the context every time you call schedule
.
server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java
Outdated
Show resolved
Hide resolved
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, it's hard to say if there are usages today that rely on the current default. Although scratching the context can make more harm than preserving it so I think we're on the right side with this change.
I thought about this initially, and looked at a lot of callers, coming to the conclusion that I couldn't find any place where not preserving the calling context would make sense. Adding a boolean would i think add more confusion, and can still be introduced if we have an actual case where we need it. |
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 then!
Changes ThreadPool's schedule method to run the schedule task in the context of the thread that scheduled the task. This is the more sensible default for this method, and eliminates a range of bugs where the current thread context is mistakenly dropped. Closes #17143
Changes ThreadPool's
schedule
method to run the schedule task in the context of the thread that scheduled the task.This is the more sensible default for this method, and eliminates a range of bugs where the current thread context is mistakenly dropped.
Closes #17143