Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Race condition where future callbacks invoked before client is in paused state #1145

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mukund-ananthu
Copy link
Contributor

For non-retriable errors returned from the backend, the client library currently sets future.set_exception() for all outstanding futures:

for future in self._futures:
future.set_exception(exc)

before it tries to change its state to paused by calling _batch_done_callback():

if self._batch_done_callback is not None:
# Failed to publish batch.
self._batch_done_callback(batch_transport_succeeded)

which transitions the state of the client library to a paused state:

else:
# Unrecoverable error detected
self._pause()

This results in race conditions where the callback associated with the future is invoked before the client enters paused state. This causes issues if the callback attempts to do a resume_publish() before the client is in the paused state.

This fix ensures that the client is in paused state before future callbacks are invoked as a consequence of future.set_exception

Fixes #1144 馃

@mukund-ananthu mukund-ananthu requested review from a team as code owners April 14, 2024 23:53
@product-auto-label product-auto-label bot added size: xs Pull request size is extra small. api: pubsub Issues related to the googleapis/python-pubsub API. labels Apr 14, 2024
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 googleapis/python-pubsub API. size: xs Pull request size is extra small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Publisher Client does not enter paused state before future.set_exception
1 participant