Skip to content

Commit

Permalink
fix: shutdown error on streaming pull callback error (#40)
Browse files Browse the repository at this point in the history
* fix: shutdown error on streaming pull callback error

* fix incorrect comment
  • Loading branch information
plamut committed Feb 28, 2020
1 parent 380cb38 commit 552539e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions google/cloud/pubsub_v1/subscriber/futures.py
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
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

0 comments on commit 552539e

Please sign in to comment.