-
Notifications
You must be signed in to change notification settings - Fork 36
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 dropping TLS for detached futures #139
Conversation
When a detached future is being cleaned up after the end of an execution, it won't be able to access the current task's storage any more. We need to bail out early from the cleanup to avoid a panic.
ab1b48b
to
30ba405
Compare
// If we've finished execution already (this task was detached), don't clean up. We | ||
// can't access the state any more to destroy thread locals, and don't want to run | ||
// any more wakers (which will be no-ops anyway). | ||
if ExecutionState::try_with(|state| state.is_finished()).unwrap_or(true) { | ||
return Poll::Ready(()); | ||
} |
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.
Why are we still polling the future if execution already finished?
Was the task's local storage already dropped in ExecutionState::cleanup
when we drained tasks?
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.
We're not re-polling the future after execution finishes. But at ExecutionState::cleanup
time, we drop the continuation, which for unfinished tasks involves resuming the task so that it can unwind its stack. That's how we end up in this code. We do still clean up the task's local storage inExecutionState::cleanup
, so this change isn't actually leaking anything, just changing where the cleanup happens.
|
||
struct ShuttleSpawn; | ||
|
||
impl Spawn for ShuttleSpawn { |
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 - didn't know about the Spawn
trait.
The Shuttle issue was fixed by awslabs/shuttle#139 Signed-off-by: James Bornholt <bornholt@amazon.com>
The Shuttle issue was fixed by awslabs/shuttle#139 Signed-off-by: James Bornholt <bornholt@amazon.com>
When a detached future is being cleaned up after the end of an
execution, it won't be able to access the current task's storage any
more. We need to bail out early from the cleanup to avoid a panic.
I also fixed two small issues:
Span::record
call, despite only specifying an earlier version.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.