Skip to content

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
@mukund-ananthu
Copy link
Contributor Author

@kamalaboulhosn Bumping this up.

@mukund-ananthu mukund-ananthu enabled auto-merge (squash) June 10, 2024 14:23
@mukund-ananthu mukund-ananthu merged commit d12bac6 into main Jun 10, 2024
@mukund-ananthu mukund-ananthu deleted the pause branch June 10, 2024 16:07
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
2 participants