fix(pubsub/v2): avoid Receive hang on context cancellation#13114
Merged
hongalex merged 2 commits intoOct 14, 2025
Conversation
hongalex
previously approved these changes
Oct 13, 2025
hongalex
left a comment
Member
There was a problem hiding this comment.
Thanks for filing an issue and providing the fix!
hongalex
reviewed
Oct 13, 2025
Co-authored-by: Alex Hong <9397363+hongalex@users.noreply.github.com>
hongalex
approved these changes
Oct 14, 2025
bhshkh
approved these changes
Oct 14, 2025
hongalex
pushed a commit
that referenced
this pull request
Oct 14, 2025
🤖 I have created a release *beep* *boop* --- ## [2.2.1](pubsub/v2/v2.2.0...pubsub/v2/v2.2.1) (2025-10-14) ### Bug Fixes * **pubsub/v2:** Avoid Receive hang on context cancellation ([#13114](#13114)) ([e7e169d](e7e169d)) * **pubsub/v2:** Upgrade gRPC service registration func ([8fffca2](8fffca2)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #13113
Cause of the Issue
In v2.0, when the context was canceled, all messages were Nacked.
However, starting from v2.1, when the context is canceled, even if a message has already been received via iter.receive()
, the implementation returns without calling Nack().
As a result, since v2.1, iterator.done() may not be executed for some keys, which causes the condition len(it.keepAliveDeadlines) == 0 to never be satisfied.
Consequently, the program remains blocked at the section where it.wg.Wait() is called, which in turn causes Receive’s group.Wait() to remain blocked as well, resulting in a hang.
Summary of the Fix
Modified the behavior so that no further messages are received once the context is canceled.