Skip to content

impl(pubsub): subscriber shutdown#5251

Merged
dbolduc merged 2 commits intogoogleapis:mainfrom
dbolduc:impl-pubsub-shutdown-outside-of-stream
Apr 3, 2026
Merged

impl(pubsub): subscriber shutdown#5251
dbolduc merged 2 commits intogoogleapis:mainfrom
dbolduc:impl-pubsub-shutdown-outside-of-stream

Conversation

@dbolduc
Copy link
Copy Markdown
Member

@dbolduc dbolduc commented Apr 2, 2026

Part of the work for #5024

Support a shutdown, signaled by the application (via a ShutdownToken, or by dropping the stream), and after a permanent error.

None of this is public. The next PR will make it public and add the proper documentation for the shutdown_token() accessor.

I couldn't really break this down without regressing existing behavior. And in the middle of the release, that seemed like a bad idea.

@product-auto-label product-auto-label bot added the api: pubsub Issues related to the Pub/Sub API. label Apr 2, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 98.84393% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.98%. Comparing base (2726737) to head (f3d2cab).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/pubsub/src/subscriber/message_stream.rs 98.82% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #5251    +/-   ##
========================================
  Coverage   97.98%   97.98%            
========================================
  Files         215      215            
  Lines       44755    44904   +149     
========================================
+ Hits        43852    43999   +147     
- Misses        903      905     +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbolduc dbolduc marked this pull request as ready for review April 2, 2026 19:27
@dbolduc dbolduc requested a review from a team as a code owner April 2, 2026 19:27
let shutdown_clone = shutdown.clone();
let _shutdown_guard = shutdown.clone().drop_guard();
tokio::spawn(async move {
// Hold the strong senders for the channels, dropping them when an
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: can you make clear that this is the only place that is allowed to hold the strong version? That way we don't come back in later and try to do a refactor to pass the Strong Sender somewhere else, without realizing there are consequences.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

without realizing there are consequences.

The unit tests will definitely fail.

this is the only place that is allowed to hold the strong version?

Well, this is the only place in the MessageStream. The Handlers all get a strong ack_tx. And the lease loop might be holding a strong message_tx, depending on the configured shutdown behavior. 🫨

As I write this, I agree with your main point that this is not clear, unnecessarily complicated. So, #5255.

I am going to merge this PR first, and get the feature done, then spend an hour or two trying to build the background task into the LeaseLoop. And have the LeaseLoop outputs be weak senders + the cancellation token. Which seems like a clearer/cleaner approach.

pub fn shutdown_token(&self) -> ShutdownToken {
ShutdownToken {
inner: self.shutdown.clone(),
fut: self.lease_loop.clone(),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Returning self.lease_loop was unexpected when I read this. Maybe a comment to explain that "The lease_loop exits once shutdown is complete" or "shutdown is considered complete when the lease loop has ended".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The member variable says exactly this:

/// This future is ready when the lease loop shutdown completes.
lease_loop: Shared<BoxFuture<'static, ()>>,

I guess I can duplicate the comment.

Aside: it was probably surprising because my names are bad. Maybe shutdown should be cancel and lease_loop should be shutdown. WDYT?

@dbolduc dbolduc enabled auto-merge (squash) April 3, 2026 16:35
@dbolduc dbolduc merged commit c295557 into googleapis:main Apr 3, 2026
36 checks passed
@dbolduc dbolduc deleted the impl-pubsub-shutdown-outside-of-stream branch April 3, 2026 16:46
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 Pub/Sub API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants