-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
PubSub: deadlock when cancelling a subscribe call #8616
Comments
@plamut Can you take a look? |
I can check, but only in a few days time at earliest. |
@plamut No worries, seems like an odd edge case. |
As far as I can see:
This is also locking against the production pubsub |
I can confirm this issue is reproducible. Digging through the code, it appears that it sometimes gets stuck while trying to get the next response from the
When this occurs, I see several calls to
Could this be a bug in the gRPC itself? In what cases does the Update:
The background stream is re-opened, and the same thing happens again when calling The main thread does not see that, though, and remains blocked at the |
I wonder if this issue is related to #7826. In that issue, the |
Maybe, I can try that when #8650 is merged. |
@plamut I merge it today. |
I tried leveraging the new I also noticed that this does not happen if a tiny delay is inserted between the future = subscriber.subscribe(sub, lambda msg: None)
logger.info('\x1b[1mRun %d cancelling \x1b[0m', i)
time.sleep(0.01) # <--- This seems to avoid the problem
future.cancel() With that, I had the test script successfully running for more than 7800 iterations, cancelling the subscriptions as expected, after which I terminated it. Of course, this is not a proper fix. It seems that cancelling the stream too early causes something weird to happen in |
This deadlock happens in google-cloud-python/api_core/google/api_core/bidi.py Lines 693 to 703 in 20ebf60
The blocking call to |
Toward clean shutdown of the subscriber's background thread. See: #8616.
…s#9337) Avoid blocking for ill-behaved daemon threads during BiDi shutdown. Closes googleapis#8616, googleapis#9008.
Environment details
Steps to reproduce
Running cancel very soon after the
subscriber.subscribe
call leads to a deadlock. See example code below, that stops after between 0 and 4 loops on my computer.Code example
Stack trace
The text was updated successfully, but these errors were encountered: