Skip to content
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

PubSub: dispatch_callback errors after cancel() of a subscription #6130

Closed
udim opened this issue Sep 28, 2018 · 5 comments · Fixed by #8111
Closed

PubSub: dispatch_callback errors after cancel() of a subscription #6130

udim opened this issue Sep 28, 2018 · 5 comments · Fixed by #8111
Assignees
Labels
api: pubsub Issues related to the Pub/Sub API. priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@udim
Copy link

udim commented Sep 28, 2018

OS: Linux 4.17.0-3rodete2-amd64, Debian 4.17.17-1rodete2
Python 2.7.13
google-cloud-pubsub 0.35.4

Stacktrace 1

ERROR:google.cloud.pubsub_v1.subscriber._protocol.helper_threads:Error in queue callback worker: 'NoneType' object has no attribute 'is_paused'
Traceback (most recent call last):
  File "/usr/local/google/home/ehudm/virtualenvs/beamenv/local/lib/python2.7/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/helper_threads.py", line 112, in __call__
    self._callback(items)
  File "/usr/local/google/home/ehudm/virtualenvs/beamenv/local/lib/python2.7/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py", line 101, in dispatch_callback
    self.ack(batched_commands.pop(requests.AckRequest))
  File "/usr/local/google/home/ehudm/virtualenvs/beamenv/local/lib/python2.7/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py", line 124, in ack
    self.drop(items)
  File "/usr/local/google/home/ehudm/virtualenvs/beamenv/local/lib/python2.7/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py", line 133, in drop
    self._manager.maybe_resume_consumer()
  File "/usr/local/google/home/ehudm/virtualenvs/beamenv/local/lib/python2.7/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py", line 224, in maybe_resume_consumer
    if not self._consumer.is_paused:
AttributeError: 'NoneType' object has no attribute 'is_paused'

Stacktrace 2

ERROR:google.cloud.pubsub_v1.subscriber._protocol.helper_threads:Error in queue callback worker: 'NoneType' object has no attribute 'remove'
Traceback (most recent call last):
  File "/usr/local/google/home/ehudm/virtualenvs/beamenv/local/lib/python2.7/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/helper_threads.py", line 112, in __call__
    self._callback(items)
  File "/usr/local/google/home/ehudm/virtualenvs/beamenv/local/lib/python2.7/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py", line 101, in dispatch_callback
    self.ack(batched_commands.pop(requests.AckRequest))
  File "/usr/local/google/home/ehudm/virtualenvs/beamenv/local/lib/python2.7/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py", line 124, in ack
    self.drop(items)
  File "/usr/local/google/home/ehudm/virtualenvs/beamenv/local/lib/python2.7/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py", line 132, in drop
    self._manager.leaser.remove(items)
AttributeError: 'NoneType' object has no attribute 'remove'

Steps to reproduce

event = threading.Event()
def message_cb(msg):
  msg.ack()
  event.set()
sub_client = pubsub.SubscriberClient()
sub_future = sub_client.subscribe(sub_name, message_cb)
event.wait()
sub_future.cancel()

This subscription should be canceled approximately after the first message. In my test there are two messages sent to the topic and event.set() is called after the second.

I realize that calling cancel() so soon prevents the ack from being sent. Is there a cleaner way to stop the subscription?

@tseaver tseaver added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. api: pubsub Issues related to the Pub/Sub API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: question Request for information or clarification. Not an issue. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Sep 28, 2018
@tseaver
Copy link
Contributor

tseaver commented Sep 28, 2018

@theacodes I'm not sure how cancellation should work. Can you clairify?

@theacodes
Copy link
Contributor

Cancellation tries to be as "fast" as possible, as waiting for all currently held messages to resolve is basically the halting problem. We should probably update the docs there to mention that.

More serious is the fact that there doesn't seem to be a "clean" shutdown here. I'm going to assign over to @crwilcox to handle, but really the fix should be straightforward (be more defensive when trying to invoke things on the streaming pull manager that could be in the process of shutting down)

@theacodes theacodes assigned crwilcox and unassigned theacodes Sep 28, 2018
@tseaver
Copy link
Contributor

tseaver commented Oct 18, 2018

@theacodes, @crwilcox Should this be categorized as a bug, then?

@sduskis sduskis assigned plamut and unassigned crwilcox May 20, 2019
@sduskis sduskis added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed type: question Request for information or clarification. Not an issue. labels May 20, 2019
@sduskis
Copy link
Contributor

sduskis commented May 20, 2019

@plamut, can you please take a look at this?

@JustinBeckwith JustinBeckwith added the 🚨 This issue needs some love. label May 20, 2019
@plamut
Copy link
Contributor

plamut commented May 23, 2019

The first manifestation of the issue (stacktrace 1) is the issue #5751, which has been fixed and released. However, I was able to reproduce the second issue (stacktrace 2) even with the latest PubSub version (0.41.0 at the time of writing) - an exception can occur in the background threads upon shutdown, particularly in the callback dispatcher thread.

It appears that some extra checks need to be added when interacting with the streaming pull manager, because the latter could be in the process of shutting down (as @theacodes already mentioned).

Working on a fix.

Update: Fixed, opened a PR.

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 Pub/Sub API. priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants