-
Notifications
You must be signed in to change notification settings - Fork 206
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Replace asserts with None checks for graceful shutdown #1244
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
product-auto-label
bot
added
size: m
Pull request size is medium.
api: pubsub
Issues related to the googleapis/python-pubsub API.
labels
Sep 9, 2024
🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use -- conventional-commit-lint bot |
mukund-ananthu
added
the
kokoro:force-run
Add this label to force Kokoro to re-run the tests.
label
Sep 9, 2024
yoshi-kokoro
removed
the
kokoro:force-run
Add this label to force Kokoro to re-run the tests.
label
Sep 9, 2024
@parthea PTAL. |
parthea
approved these changes
Sep 9, 2024
hongalex
approved these changes
Sep 9, 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: m
Pull request size is medium.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are two code paths that race to set / read the value of
self._scheduler
variable of streaming_pull_managerCode path 1
future.cancel()
:python-pubsub/google/cloud/pubsub_v1/subscriber/futures.py
Lines 56 to 76 in 5402b62
calls
streaming_pull_manager.close()
:python-pubsub/google/cloud/pubsub_v1/subscriber/futures.py
Line 75 in 5402b62
which schedules the
_shutdown
method:python-pubsub/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py
Lines 896 to 902 in 5402b62
that sets the
self._scheduler
variable to None using a lockself._closing
:python-pubsub/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py
Lines 912 to 929 in 5402b62
Code Path 2
The streaming_pull_manager's
_on_response
method:python-pubsub/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py
Lines 1106 to 1129 in 5402b62
self._scheduler
variable is not None before proceeding to use it for processing further.Since the two code paths use different locks and are running on different threads, there are times when code path1 sets the
self._scheduler
value to None, while the_on_response
method is still executing. The assert in the_on_response
method fails causing an assertion error to be thrown. This happens when the library tries to process streaming pull responses when the library is also being shut down.This change replaces the asserts with a None check that would return early and stop processing(same behavior as an assert minus the error being thrown), resulting in a graceful shutdown of the library without red herring errors being logged to the user.
Fixes #997 🦕