Skip to content

fix(pubsub): handle shutdown behavior for publisher#4622

Merged
suzmue merged 4 commits intogoogleapis:mainfrom
suzmue:shutdown
Feb 10, 2026
Merged

fix(pubsub): handle shutdown behavior for publisher#4622
suzmue merged 4 commits intogoogleapis:mainfrom
suzmue:shutdown

Conversation

@suzmue
Copy link
Copy Markdown
Collaborator

@suzmue suzmue commented Feb 9, 2026

During the normal flow of using a publisher, the background task itself should not be dropped. When the task containing the Publisher is shutting down however, the background task may be forcefully aborted before the task that is processing the results of the publish. This will result in any resources owned by the background task to be dropped, including the channel for processing incoming publish requests and any oneshot channels to be resolved for publish requests. This means that the PublishFuture must be able to handle the case where these resources are dropped without panicking.

Fixes #4483

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

codecov bot commented Feb 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.02%. Comparing base (d471fb4) to head (b18c0fe).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4622      +/-   ##
==========================================
- Coverage   95.03%   95.02%   -0.02%     
==========================================
  Files         195      195              
  Lines        7473     7477       +4     
==========================================
+ Hits         7102     7105       +3     
- Misses        371      372       +1     

☔ 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.

@suzmue suzmue marked this pull request as ready for review February 9, 2026 21:57
@suzmue suzmue requested a review from a team as a code owner February 9, 2026 21:57
}
}

#[tokio::test]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: start_paused = true

We don't want to race with the batch timer, however unlikely that is to fire first

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

addressed in #4647

handles.push(handle);
}

background_task_handle.abort();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

good idea to test this sort of thing

.expect("publisher should not close the sender for PublishFuture")
.map_err(convert_error),
)
// which can happen when the background worker is dropped.
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.

Suggested change
// which can happen when the background worker is dropped.
// which can happen when the dispatcher is dropped.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

addressed in #4647

@suzmue suzmue merged commit e624867 into googleapis:main Feb 10, 2026
34 checks passed
@suzmue
Copy link
Copy Markdown
Collaborator Author

suzmue commented Feb 10, 2026

Going to address the comments in a follow up PR, because I'd like this fix to land in the release if possible.

@suzmue suzmue deleted the shutdown branch February 10, 2026 18:23
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.

Gracefully handle forced shutdown for Publish background tasks

3 participants