Skip to content

Conversation

@feywind
Copy link
Collaborator

@feywind feywind commented May 6, 2025

Implements a new timeout and behavior option (using Duration) for the Subscription.close() method. These options are on the SubscriberOptions/SubscriptionOptions passed in when opening a subscriber.

This provides more control over the shutdown process:

  • The subscriber stream is closed immediately.
  • If the behaviour is set to NackImmediately, then all buffered messages are nacked, and the timeout specifies how long to wait for them to go through.
  • If the behaviour is set to WaitForProcessing, then the remaining message machinery continues until the timeout is almost up, and then it switches to NackImmediately.
  • If the timeout is zero, everything closes down immediately, as quickly as possible.

Implements a new `timeout` option (using `Duration`) for the `Subscription.close()` method.

This provides more control over the shutdown process:
- If `timeout` is zero, the subscription closes as quickly as possible without nacking buffered messages.
- If `timeout` is positive, the subscription attempts to nack any buffered messages (in the lease manager) and waits up to the specified duration for pending acknowledgements and nacks to be sent to the server.
- If no timeout is provided, the behavior remains as before (waits indefinitely for pending acks/modacks, no nacking).

The core logic is implemented in `Subscriber.close()`. `PubSub.close()` documentation is updated to clarify its scope and recommend using `Subscription.close()` directly for this feature.

Includes:
- Unit tests for the new timeout behavior in `Subscriber.close()`.
- A TypeScript sample (`samples/closeSubscriptionWithTimeout.ts`) demonstrating usage.
- Updated JSDoc documentation for relevant methods.
@feywind feywind requested review from a team as code owners May 6, 2025 22:16
@snippet-bot
Copy link

snippet-bot bot commented May 6, 2025

No region tags are edited in this PR.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@generated-files-bot
Copy link

Warning: This pull request is touching the following templated files:

@product-auto-label product-auto-label bot added size: l Pull request size is large. api: pubsub Issues related to the googleapis/nodejs-pubsub API. labels May 6, 2025
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. and removed size: l Pull request size is large. labels Jun 20, 2025
@feywind feywind added the owlbot:run Add this label to trigger the Owlbot post processor. label Jun 20, 2025
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jun 20, 2025
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: xl Pull request size is extra large. labels Jun 20, 2025
@feywind feywind added the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 8, 2025
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 8, 2025
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. and removed size: l Pull request size is large. labels Jul 8, 2025
@feywind feywind added the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 8, 2025
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 8, 2025
@feywind
Copy link
Collaborator Author

feywind commented Jul 16, 2025

Migrated to #2068 to get CI.

@feywind feywind closed this Jul 16, 2025
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 googleapis/nodejs-pubsub API. size: xl Pull request size is extra large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant