Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

fix: Align Stream Closure Errors with Canonical API Behavior#1416

Closed
abbrowne126 wants to merge 10 commits intogoogleapis:mainfrom
abbrowne126:fix-stream-closure-errors
Closed

fix: Align Stream Closure Errors with Canonical API Behavior#1416
abbrowne126 wants to merge 10 commits intogoogleapis:mainfrom
abbrowne126:fix-stream-closure-errors

Conversation

@abbrowne126
Copy link
Copy Markdown
Collaborator

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #1415, #1176

@abbrowne126 abbrowne126 requested review from a team May 27, 2025 16:29
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label May 27, 2025
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/python-pubsub API. label May 27, 2025
Comment thread google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py Outdated
exceptions.GatewayTimeout,
exceptions.Aborted,
)
_TERMINATING_STREAM_ERRORS = (exceptions.Cancelled,)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems that the reasoning for the use of Cancelled as a terminating stream error here is to prevent errors logs for what should be "clean" shutdowns (googleapis/google-cloud-python#8650 (comment)), so I wonder if this might cause exceptions like (googleapis/google-cloud-python#7826) to be thrown. Another worry is that we won't get exceptions for the new TERMINATING_STREAM_ERRORS, though I'm admittedly not certain how the mechanism actually works.

Copy link
Copy Markdown
Collaborator Author

@abbrowne126 abbrowne126 May 27, 2025

Choose a reason for hiding this comment

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

I aligned this with the other client libs (ex Java, ex CPP) but this is a fair point - I believe these cancelled would actually be client initiated in this case so I'll keep it in terminating.

As for the exceptions/no exceptions, this will close the thread; this was already WAI for the library. Here's the details for ServiceConsumer (i.e. specific to our implementation):

As for how the behavior works with termination, this is already covered in unit tests. Specific to the future, here's an example of where the error -> client-visible exception is tested

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for spelling out the details here, definitely makes a lot more sense now. This all looks good to me, just want to confirm if you've tested this with local changes and a reproduction of throwing an exception in BackgroundConsumer._thread_main.

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.

Yes - granted, the test involved mocking the ResumableBidiRpc but otherwise it was the same testing process. I saw the error bubbled to the future.

@googleapis googleapis deleted a comment from harshvardhanrajdan May 28, 2025
@abbrowne126 abbrowne126 marked this pull request as draft May 29, 2025 19:00
@michaelpri10
Copy link
Copy Markdown
Contributor

Sample failures seem to be due to SMTs, so are unrelated to this PR.

@harshvardhanrajdan
Copy link
Copy Markdown

@abbrowne126 please update the status?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: pubsub Issues related to the googleapis/python-pubsub API. size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Align Stream Retry and Termination Behavior With Canonical API Retry Policies; Surface Fatal Errors Immediately

3 participants