feat(pubsub/v2): add subscriber shutdown options#12829
Conversation
1178bd6 to
1a9e6de
Compare
feywind
left a comment
There was a problem hiding this comment.
I'm not a Go Pub/Sub expert, but this looks like it generally does what it's supposed to :)
shollyman
left a comment
There was a problem hiding this comment.
The use of new context.Background() in iterator looks a bit odd, but LGTM given our discussions.
To capture our offline discussions, a detached context.Background() always existed in the iterator (so in flight messages are not cancellable by the user by default). This matches the default behavior. I needed to introduce a context finally because |
🤖 I have created a release *beep* *boop* --- ## [2.1.0](pubsub/v2/v2.0.1...pubsub/v2/v2.1.0) (2025-09-25) ### Features * **pubsub/v2:** Add subscriber shutdown options ([#12829](#12829)) ([14c3887](14c3887)) --- 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>
|
Hi @hongalex , |
|
Approved the above PR but responding here for completeness. This was indeed a bug, the Behavior should have been checked here (thanks for the PR). The interaction between Behavior/Timeout is this:
|
|
@hongalex Thank you for your kind explanation. I understand. |
Previously, `ShutdownOptions.Behavior` was never respected — when a positive `Timeout` was set, messages were always nacked. This PR fixes the shutdown logic so that messages are only nacked if `Behavior` is explicitly set to `ShutdownBehaviorNackImmediately`. This makes the `Behavior` field effective as intended. related to #12829
This introduces the ability to tell the client library how you want your messages to behave when shutdown is initiated. You can configure the behavior as
ShutdownOptions.BehaviorasShutdownBehaviorWaitForProcessingorShutdownBehaviorNackImmediately.In addition, you can specify
ShutdownOptions.Timeoutto configure how long you want to wait for messages to be processed, or provide a timeout to the nack calls before returning.