Skip to content

fix(pubsub): permanent errors end stream#4849

Merged
dbolduc merged 3 commits intogoogleapis:mainfrom
dbolduc:fix-pubsub-respect-permanent-stream-errors
Mar 2, 2026
Merged

fix(pubsub): permanent errors end stream#4849
dbolduc merged 3 commits intogoogleapis:mainfrom
dbolduc:fix-pubsub-respect-permanent-stream-errors

Conversation

@dbolduc
Copy link
Copy Markdown
Member

@dbolduc dbolduc commented Mar 1, 2026

Fixes #4848

Track whether the stream has failed with a permanent error. If so, stop trying to recreate the stream, if the application asks for more messages.

This is as Rust-y as I could get it, but I still needed an unreachable!() after the state update. 🤷

StreamState may grow to include Shutdown in the future. (Or we may just use Failed to mean Shutdown, kinda how we use Unstarted to also mean ShouldRetry). Open to naming suggestions here.

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

codecov bot commented Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.61%. Comparing base (df77ebc) to head (4d618d6).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4849   +/-   ##
=======================================
  Coverage   94.60%   94.61%           
=======================================
  Files         208      208           
  Lines        8143     8148    +5     
=======================================
+ Hits         7704     7709    +5     
  Misses        439      439           

☔ 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 March 1, 2026 09:10
@dbolduc dbolduc requested a review from a team as a code owner March 1, 2026 09:10
/// If a stream is not yet open, this method opens the stream.
async fn mut_stream(&mut self) -> Result<&mut Stream<Transport>> {
if self.stream.is_none() {
async fn mut_stream(&mut self) -> Option<Result<&mut Stream<Transport>>> {
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.

Not pretty, I think returning &mut Stream<Transport> is causing you grief, maybe you should just have a function that returns Option<Result< Message Type >. Or maybe your StreamState should implement next_message(start: AsyncFn() -> Result<Stream::<Transport>> and you just call that function on it with:

self.stream_state.next_message(async || { Stream::<Transport>::new(self.inner.clone(), self.initial_req.clone()).await  })

The lifetimes could get tricky on that, maybe.

Copy link
Copy Markdown
Member Author

@dbolduc dbolduc Mar 2, 2026

Choose a reason for hiding this comment

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

With apologies to the archaeologists, I did some refactoring in this PR.

I took your suggestions and split out (1) opening the stream and (2) receiving the next response from the stream. And also your suggestion on naming from: #4381 (review)

I think the code reads a lot nicer, so thanks.

@dbolduc dbolduc merged commit 724c7eb into googleapis:main Mar 2, 2026
35 checks passed
@dbolduc dbolduc deleted the fix-pubsub-respect-permanent-stream-errors branch March 2, 2026 06:15
dbolduc added a commit that referenced this pull request Mar 2, 2026
I was a bit too trigger happy on merging #4849. This is my final answer
for how to spell the code.
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.

Subscriber streams should not be retried after permanent error

2 participants