Skip to content

feat: add timeout option and graceful shutdown to Subscription.close() #2037

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

feywind
Copy link
Collaborator

@feywind feywind commented May 6, 2025

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 behaviour remains as before (waits indefinitely for pending acks/modacks, no nacking).

WIP!

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
Copy link

snippet-bot bot commented May 6, 2025

Here is the summary of changes.

You are about to add 1 region tag.

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

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
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: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant