GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add timeout option and graceful shutdown to Subscription.close() by feywind · Pull Request #2068 · googleapis/nodejs-pubsub

This repository was archived by the owner on Oct 21, 2026. It is now read-only.

Conversation

@feywind

@feywind feywind commented Jul 16, 2025

Copy link
Copy Markdown
Contributor

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.

(This is a re-open of #2037 to make it from the main repo.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
google-labs-jules Bot and others added 16 commits May 6, 2025 22:15
@google-labs-jules
feat: Add timeout option to Subscription.close()
24c37bb
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
docs: revert README change so release-please can do it
687212d
@feywind
feat: jules' vibin' is too lo-fi, fix some bad assumptions
da726d0
@feywind
samples: typeless a JS sample for close with timeout
629aa43
@feywind
feat: add awaitWithTimeout and test
a0ba234
@feywind
tests: also test error results without timeout
13e58f2
@feywind
feat: update for the current spec, test updates coming
5db179e
@feywind
tests: misc fixes before further additions
62afe56
@feywind
feat: update Temporal shims to match latest standards
b904884
@feywind
chore: linter fix
2cf219f
@feywind
feat: update to latest spec doc info, finish unit tests
6e41e4d
@feywind
Merge branch 'main' into feat-close-timeout
49003e9
@feywind
feat: also move the options from close() parameters to subscriber opt…
ca50c3c
…ions
@feywind
chore: fix linter errors
ce5e917
@feywind
samples: update to latest API changes
f2898a3
@gcf-owl-bot @feywind
🦉 Updates from OwlBot post-processor
073c6d7
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
@feywind
feywind requested review from a team July 16, 2025 17:48
@product-auto-label product-auto-label Bot added size: xl Pull request size is extra large. api: pubsub Issues related to the googleapis/nodejs-pubsub API. labels Jul 16, 2025
@feywind feywind mentioned this pull request Jul 16, 2025
feat: add timeout option and graceful shutdown to Subscription.close() #2037
Closed
@feywind feywind added the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 16, 2025
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 16, 2025
gcf-owl-bot Bot added 3 commits July 16, 2025 17:53
@gcf-owl-bot
🦉 Updates from OwlBot post-processor
bcad5e7
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
@gcf-owl-bot
🦉 Updates from OwlBot post-processor
f28be03
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
@gcf-owl-bot
Merge branch 'feat-close-timeout' of https://github.com/googleapis/no…
9aabe08
…dejs-pubsub into feat-close-timeout
sofisl
sofisl previously approved these changes Jul 16, 2025
View reviewed changes
Comment thread src/exponential-retry.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/subscriber.ts
const remaining = this._inventory.clear();

await this._waitForFlush();
const options = this._options.closeOptions;

@sofisl sofisl Jul 16, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

optional chaining?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feywind feywind Aug 6, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

this._options is guaranteed to be non-undefined, so I don't think it's necessary here. The lines that use options do optional chaining, since closeOptions may be undefined.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/subscriber.ts
// The timeout can't realistically be longer than the longest time we're willing
// to lease messages.
let timeout = durationAtMost(
options?.timeout ?? this.maxExtensionTime,

@sofisl sofisl Jul 16, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

is maxExtensionTime a const? How do we know it will be available? If the former, maybe worth uppercasing?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feywind feywind Aug 6, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It's a config option with a default. So it's set by the constructor:

this.maxExtensionTime = defaultOptions.subscription.maxExtensionTime;

And then if the user passed a value, it overwrites the default.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/subscriber.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/temporal.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

miguelvelezsa
miguelvelezsa reviewed Jul 18, 2025
View reviewed changes

@miguelvelezsa miguelvelezsa left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I would highly recommend to add types in all the new code :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/lease-manager.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/subscriber.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/subscriber.ts
*
* @private
*/
dispatched(): void {

@miguelvelezsa miguelvelezsa Jul 18, 2025

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

should be dispatch()?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feywind feywind Aug 6, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It's less of a command, more of an event. Basically there is something else doing dispatching, and this method is called to notify telemetry and such. So I don't think I'd call it dispatch, but I'm open to other ideas.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/subscriber.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/subscriber.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/subscriber.ts Outdated
Comment on lines +981 to +982
const err = e as [unknown, boolean];
if (err[1] === false) {

@miguelvelezsa miguelvelezsa Jul 18, 2025

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

for my own knowledge, how err[1] === true means was timeout? probably adding type for 'e' here will help :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feywind feywind Jul 21, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yeah, this has to do with implementing the time-limited Promise wait... it's super annoying to make graceful. I'll look again.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@feywind feywind Aug 6, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Not sure why it didn't give me a separate box for comments on the one above, but check out Sofia's comment on why I did this like I did.

I agree with you on the second one. I'll add an interface.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/subscriber.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/subscriber.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@feywind

feywind commented Jul 21, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I would highly recommend to add types in all the new code :)

Can you elaborate here? The only time I tend to omit them is when they're super obvious (like making a class member like foo = new Map<string, string>()). I might've missed some : void on function returns.

Edit: it didn't tag you :) @miguelvelezsa

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@feywind feywind added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jul 22, 2025
@feywind

feywind commented Jul 22, 2025

Copy link
Copy Markdown
Contributor Author

I need to look at a few more review comments before merging anything.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@feywind feywind mentioned this pull request Aug 1, 2025
feat: Attempted implemented graceful shutdown #1855
Closed
4 tasks
feywind added 7 commits August 6, 2025 16:01
@feywind
fix: no need to check isEmpty on remove
8866c98
@feywind
chore: merge remote-tracking branch 'refs/remotes/origin/feat-close-t…
82e0c81
…imeout' into feat-close-timeout
@feywind
chore: merge remote-tracking branch 'remotes/origin/main' into feat-c…
f08ae6d
…lose-timeout
@feywind
chore: remove unneeded promise skip code
791a7f0
@feywind
fix: substantially clarify the awaitWithTimeout interface
36e5361
@feywind
chore: hoist timeout logic into its own method
d3a3489
@feywind
fix: tests were leaking EventEmitter handlers
a285935
@feywind
feywind dismissed sofisl’s stale review via a285935 August 6, 2025 21:02
@generated-files-bot

generated-files-bot Bot commented Aug 6, 2025

Copy link
Copy Markdown

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

  • README.md - README.md is managed by synthtool. However, a partials file can be used to update the README, e.g.: https://github.com/googleapis/nodejs-storage/blob/main/.readme-partials.yaml
  • samples/README.md - samples/README.md is managed by synthtool. However, a partials file can be used to update the README, e.g.: https://github.com/googleapis/nodejs-storage/blob/main/.readme-partials.yaml
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@feywind
chore: change constant to CONSTANT_CASE
abeeb6c
@feywind feywind added owlbot:run Add this label to trigger the Owlbot post processor. and removed do not merge Indicates a pull request not ready for merge, due to either quality or timing. labels Aug 6, 2025
@gcf-owl-bot gcf-owl-bot Bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Aug 6, 2025
sofisl
sofisl approved these changes Aug 7, 2025
View reviewed changes
@feywind
feywind merged commit 8dee024 into main Aug 7, 2025
@feywind
feywind deleted the feat-close-timeout branch August 7, 2025 17:57
@release-please release-please Bot mentioned this pull request Jul 22, 2025
chore(main): release 5.2.0 #2073
Merged
nico-kn
nico-kn reviewed Dec 5, 2025
View reviewed changes
Comment thread src/subscriber.ts
Comment on lines +1001 to +1004
if (
behavior === SubscriberCloseBehaviors.WaitForProcessing &&
!this._inventory.isEmpty
) {

@nico-kn nico-kn Dec 5, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Was just debugging the WaitForProcessing functionality locally and stumbled upon this check.

@feywind wouldn't this need to be the following? isEmpty seems to be undefined, instead this might have to be a method call?

Suggested change
if (
behavior === SubscriberCloseBehaviors.WaitForProcessing &&
!this._inventory.isEmpty
) {
if (
behavior === SubscriberCloseBehaviors.WaitForProcessing &&
!this._inventory.isEmpty()
) {

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@nico-kn nico-kn Dec 8, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Created #2117 accordingly

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
This was referenced Dec 8, 2025
Shutdown option WaitForProcessing never entered on subscription close #2117
Closed
fix(WaitForProcessing): Shutdown option WaitForProcessing never entered on subscription close nico-kn/nodejs-pubsub#1
Closed
fix(WaitForProcessing): Shutdown option WaitForProcessing never entered on subscription close #2118
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

3 more reviewers
@miguelvelezsa miguelvelezsa miguelvelezsa left review comments
@nico-kn nico-kn nico-kn left review comments
@sofisl sofisl sofisl approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: pubsub Issues related to the googleapis/nodejs-pubsub API. size: xl Pull request size is extra large.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@feywind @miguelvelezsa @nico-kn @sofisl
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.