question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: closing the subscription stream without clearing the local inventory and flushing ACKs

See original GitHub issue

Is your feature request related to a problem? Please describe.

I am looking to gracefully shutdown a service (ex: during rolling deployments) by draining remaining Pub/Sub messages without accepting new ones. Currently, this library offers an async subscription.close() method, which (1) closes the subscription stream, (2) clears the inventory of locally buffered messages, and (3) waits to flush all ACKs/NACKs: https://github.com/googleapis/nodejs-pubsub/blob/f8203ef0ffb8edb7f5b1ce7dfb37104d8890f476/src/subscriber.ts#L297-L308

The issue with close() is that the local inventory (in the LeaseManager instance) is cleared, which means those messages won’t get handled until their ack deadline expires and the Pub/Sub service redelivers the messages to a new subscriber.

Describe the solution you’d like

I would like to have an API to help with gracefully draining the Pub/Sub subscription. Here are two proposals:

  1. New method – subscription.pause(): pauses the underlying pull stream so that it doesn’t fetch new messages from the Pub/Sub service. The caller of this API can then pause the subscription, handle the remaining messages until the inventory is drained (perhaps expose another event to learn when the inventory is empty), and then call close() to flush all the ACKs.
  2. Make subscription.close() drain the inventory: calling close() would close the underlying pull stream, wait for the existing inventory to become empty instead of clearing it, and then wait for the ACKs to be flushed.

Describe alternatives you’ve considered In the meantime, I have a separate leasing system that deduplicates messages across Pub/Sub subscriber instances. (This was necessary because Pub/Sub has at-least-once semantics.) I could reduce the ack deadline for messages to something short, and rely on the leasing system to guard against the higher likelihood of duplicate messages.

With the shorter ack deadline, calling close() will still cause messages in the orphaned inventory to wait until their ack deadlines expire, but the deadlines will be shorter, reducing the impact of this issue.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
callmehiphopcommented, Aug 26, 2019

@ide thanks for the detailed write up! I think I would be in favor of adding an alternative method to close that would wait for all the messages to be acked/nacked before releasing the lock on them.

@kamalaboulhosn @bcoe any thoughts here?

0reactions
feywindcommented, Mar 24, 2022

Moving this into our internal backlog, but feel free to keep adding comments if needed here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ISteamNetworkingSockets Interface - Steamworks
Networking API similar to Berkeley sockets, but for games. It's a connection-oriented API (like TCP, not UDP). When sending and receiving messages, the...
Read more >
Web User Interface (WUI) – Kemp Support
Click the View License link to display model, subscription expiry, and subscription feature details, such as the activation date and end ...
Read more >
FortiGate / FortiOS 7.0.4 - Fortinet Documentation Library
DNS proxy generated local out rating (FortiGuard category) queries can time out if they are triggered for the same DNS domains with the...
Read more >
Known Issues for Oracle SOA Products 12.1.3
However, if the TIBCO server is stopped and restarted midway through the processing, the source Queue will not be flushed of read messages....
Read more >
System Center vNext Data Protection Manager error codes
If the service doesn't start, reinstall the protection agent. 35, DPM can't browse <ServerName>, either because no agent is installed on < ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found