-
Notifications
You must be signed in to change notification settings - Fork 3.9k
binder: Avoid potential deadlock when canceling AsyncSecurityPolicy futures #12283
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
base: master
Are you sure you want to change the base?
Conversation
…utures Move future cancellation outside of synchronized block in BinderClientTransport.notifyTerminated() to prevent deadlock if AsyncSecurityPolicy uses directExecutor() for callbacks. Fixes grpc#12190
Help me understand the change here? All those cancel() calls still appear to come from inside the @GuardedBy("this") method notifyTerminated() method ... |
…o fix-binder-deadlock-12190 Signed-off-by: Hyunsang Han <[email protected]>
…ted() Move future cancellation to offloadExecutor to avoid deadlock when AsyncSecurityPolicy uses directExecutor() for callbacks. Fixes grpc#12190 Signed-off-by: Hyunsang Han <[email protected]>
OMG! Sorry. I realized that I missed committing the actual fix! @jdcormie Could you please check the latest commit? |
binder/src/main/java/io/grpc/binder/internal/BinderClientTransport.java
Outdated
Show resolved
Hide resolved
binder/src/main/java/io/grpc/binder/internal/BinderClientTransport.java
Outdated
Show resolved
Hide resolved
binder/src/main/java/io/grpc/binder/internal/BinderClientTransport.java
Outdated
Show resolved
Hide resolved
Extract future cancellation logic into cancelAsync method and only cancel futures that are not already done for better performance. Signed-off-by: Hyunsang Han <[email protected]>
binder/src/main/java/io/grpc/binder/internal/BinderClientTransport.java
Outdated
Show resolved
Hide resolved
binder/src/main/java/io/grpc/binder/internal/BinderClientTransport.java
Outdated
Show resolved
Hide resolved
Rename cancelAsync to cancelAsyncIfNeeded, move future cancellation next to readyTimeoutFuture, and remove unnecessary null assignments. Signed-off-by: Hyunsang Han <[email protected]>
@jdcormie |
Woke up this morning with a small new concern: Would this PR cause us to declare the Channel terminated before all work we've enqueued on the offload Executor is complete (or cancelled) ? Take a look at how |
I agree with your concern. That's a very good point. That said, while thinking about ways to improve the code, two questions came up 🤔 :
Could you elaborate a bit more on what you meant by "move into the shutdown path instead"? I want to make sure I understand your idea fully. |
Move future cancellation outside of synchronized block in
BinderClientTransport.notifyTerminated()
to prevent deadlock ifAsyncSecurityPolicy
usesdirectExecutor()
for callbacks.Fixes #12190