Skip to content

fix: shutdown error on streaming pull callback error #40

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

Merged
merged 2 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions google/cloud/pubsub_v1/subscriber/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def __init__(self, manager):
self._cancelled = False

def _on_close_callback(self, manager, result):
if self.done():
# The future has already been resolved in a different thread,
# nothing to do on the streaming pull manager shutdown.
return

if result is None:
self.set_result(True)
else:
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/pubsub_v1/subscriber/test_futures_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ def test__on_close_callback_failure(self):

assert not future.running()

def test__on_close_callback_future_already_done(self):
future = self.make_future()

future.set_result("foo")
assert future.done()

# invoking on close callback should not result in an error
future._on_close_callback(mock.sentinel.manager, "bar")

result = future.result()
assert result == "foo" # on close callback was a no-op

def test_cancel(self):
future = self.make_future()

Expand Down