Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PubSub: deadlock when cancelling a subscribe call #8616

Closed
@arthurdarcet

Description

@arthurdarcet

Environment details

  1. OSX
  2. Python 3.7.3 in a venv
  3. google-cloud-pubsub 0.42.1

Steps to reproduce

Running cancel very soon after the subscriber.subscribe call leads to a deadlock. See example code below, that stops after between 0 and 4 loops on my computer.

Code example

import sys

from google.cloud import pubsub
from google.api_core.exceptions import NotFound

subscriber = pubsub.SubscriberClient()
publisher = pubsub.PublisherClient()

sub = subscriber.subscription_path('mocked-project', 'sub-name')
topic = publisher.topic_path('mocked-project', 'topic-name')

try: subscriber.delete_subscription(sub)
except NotFound: pass

try: publisher.delete_topic(topic)
except NotFound: pass

publisher.create_topic(topic)
subscriber.create_subscription(sub, topic)

i = 0
while True:
	future = subscriber.subscribe(sub, lambda msg: None)
	print('Run', i, 'cancelling')
	future.cancel()
	print('Cancelled')
	print('--')
	sys.stdout.flush()
	i += 1

Stack trace

^CTraceback (most recent call last):
  File "a.py", line 25, in <module>
    future.cancel()
  File "/Users/arthur/dev/.venvs/Users--arthur--dev--wyl/lib/python3.7/site-packages/google/cloud/pubsub_v1/subscriber/futures.py", line 46, in cancel
    return self._manager.close()
  File "/Users/arthur/dev/.venvs/Users--arthur--dev--wyl/lib/python3.7/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py", line 425, in close
    self._consumer.stop()
  File "/Users/arthur/dev/.venvs/Users--arthur--dev--wyl/lib/python3.7/site-packages/google/api_core/bidi.py", line 686, in stop
    self._thread.join()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 1032, in join
    self._wait_for_tstate_lock()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 1048, in _wait_for_tstate_lock
    elif lock.acquire(block, timeout):
KeyboardInterrupt

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the Pub/Sub API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions