Repository navigation
pubsub: nack unreturned messages on Subscription.Shutdown - #3848
Merged
Merged
Conversation
Shutdown now cancels in-flight ReceiveBatch calls, waits for them to finish (bounded by the Shutdown ctx), and nacks every message Receive never returned through the ack batcher, so they are redelivered without waiting for the ack deadline to expire. Drivers that can't nack are unchanged.
iamabhilaksh
marked this pull request as ready for review
November 16, 2026 12:18
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3848 +/- ##
==========================================
+ Coverage 81.52% 81.54% +0.01%
==========================================
Files 100 100
Lines 12241 12256 +15
==========================================
+ Hits 9980 9994 +14
- Misses 2260 2261 +1
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #3845, as discussed there.
Problem
Subscriptionpulls messages ahead of time, beforeReceivereturns them. IfShutdownruns while some of those messages are still waiting, nothing acks or nacks them. The service keeps them reserved for this subscription until the timeout runs out (the ack deadline on GCP, the visibility timeout on SQS, the lock on Service Bus), so other consumers can't get them for up to about a minute.This covers two kinds of messages:
ReceiveShutdownis calledChange
For drivers that support nack,
Shutdownnow:Shutdowncontext; drivers are expected to return within about a second)Drivers that can't nack (kafka, nats) behave as before. Nothing is nacked twice:
gcppubsubv2'sClosefrom #3845 skips messages that were already acked or nacked.Testing
TestShutdownNacksPrefetchedcovers waiting messages, a pull in progress atShutdown, and a driver that can't nack. Both nack cases fail on master.go test -race ./pubsub/...passes, as do kafkapubsub and rabbitpubsub against local brokers, and natspubsub.End to end: 8 workers receive and ack about half of 300 messages, then
Shutdownis called. A second subscriber measures how long the rest take to come back. The timeout was 60s everywhere.gcppubsub: on master, 67 to 76 messages per run waited 60s (3 of 3 runs). With this change, none did.gcppubsubv2: pubsub/gcppubsubv2: nack buffered messages in Close #3845 already handles this on master. With this change the nacks just go out earlier, and redelivery was under 0.1s with no duplicates. Both builds occasionally held a batch for 60s (2 and 3 of 29 runs). That comes from the client library and happens on master too.Closeran; all came back within about 16s, with no duplicates or errors.Shutdowntook under 0.5s either way.Closedoesn't cancel the consumer, which is a separate issue I'll file.