Skip to content
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

context: fix race between CancellableContext and cancel #5981

Merged
merged 1 commit into from
Jul 17, 2019

Conversation

carl-mastrangelo
Copy link
Contributor

The pendingDeadline variable is modified from the ctor of CancellableContext, but it isn't final. The cancellation can happen before the variable is assigned. It's generally bad practice to leak the this reference from the ctor to other threads anyways.

This code refactors the deadline calculation and scheduling so that pendingDeadline is modified under the lock, and the this reference is not exposed.

Discovered by TSAN.

The `pendingDeadline` variable is modified from the ctor of CancellableContext, but it isn't final.  The cancellation can happen before the variable is assigned.  It's generally bad practice to leak the this reference from the ctor to other threads anyways.

This code refactors the deadline calculation and scheduling so that `pendingDeadline` is modified under the lock, and the `this` reference is not exposed.

Discovered by TSAN.
@carl-mastrangelo carl-mastrangelo changed the title context: fix race between CancellableContext and Context context: fix race between CancellableContext and cancel Jul 13, 2019
@carl-mastrangelo carl-mastrangelo merged commit 8a9afd6 into grpc:master Jul 17, 2019
@carl-mastrangelo carl-mastrangelo deleted the ctxrace branch July 17, 2019 08:12
@carl-mastrangelo carl-mastrangelo restored the ctxrace branch August 17, 2019 01:13
@lock lock bot locked as resolved and limited conversation to collaborators Nov 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants