Skip to content

fix(pubsub/v2): avoid Receive hang on context cancellation#13114

Merged
hongalex merged 2 commits into
googleapis:mainfrom
landcelita:fix-pubsub-hang-on-context-cancel
Oct 14, 2025
Merged

fix(pubsub/v2): avoid Receive hang on context cancellation#13114
hongalex merged 2 commits into
googleapis:mainfrom
landcelita:fix-pubsub-hang-on-context-cancel

Conversation

@landcelita

@landcelita landcelita commented Oct 13, 2025

Copy link
Copy Markdown
Contributor

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.

@landcelita landcelita requested review from a team October 13, 2025 16:41
@product-auto-label product-auto-label Bot added the api: pubsub Issues related to the Pub/Sub API. label Oct 13, 2025
@hongalex hongalex added the kokoro:run Add this label to force Kokoro to re-run the tests. label Oct 13, 2025
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Oct 13, 2025
hongalex
hongalex previously approved these changes Oct 13, 2025

@hongalex hongalex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for filing an issue and providing the fix!

@hongalex hongalex changed the title fix(pubsub): avoid Receive hang on context cancellation fix(pubsub/v2): avoid Receive hang on context cancellation Oct 13, 2025
@hongalex hongalex requested a review from a team October 13, 2025 22:55
Comment thread pubsub/v2/subscriber.go Outdated
Co-authored-by: Alex Hong <9397363+hongalex@users.noreply.github.com>
@hongalex hongalex added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 14, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 14, 2025
@hongalex hongalex added the kokoro:run Add this label to force Kokoro to re-run the tests. label Oct 14, 2025
@hongalex hongalex merged commit e7e169d into googleapis:main Oct 14, 2025
61 of 62 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: pubsub Issues related to the Pub/Sub API. kokoro:run Add this label to force Kokoro to re-run the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants