GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Pub/Sub Subscriber does not catch & retry UNAVAILABLE errors · Issue #4234 · googleapis/google-cloud-python

Pub/Sub Subscriber does not catch & retry UNAVAILABLE errors #4234

New issue
Copy link
New issue
Copy link
Closed
Closed
Pub/Sub Subscriber does not catch & retry UNAVAILABLE errors#4234
Copy link
Assignees
theacodes
Labels
api: pubsubIssues related to the Pub/Sub API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@kir-titievsky
kir-titievsky
opened on Oct 20, 2017
Issue body actions

A basic Pub/Sub message consumer stops consuming messages after a retryable error (see stack trace below, but in short _Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, The service was unable to fulfill your request. Please try again. [code=8a75])>). The app does not crash but the stream never recovers and continue to receive messages. Interesting observations;

  • If I simply turn off WiFi on my laptop and run the same code, it keeps retrying until the machine is connected to the network and functions as expected. This tells me that this is a reaction to the specific StatusCode
  • The exception sometimes happens on startup sometimes mid-stream.

Expected behavior:

  • The application code would continue retrying to build the streamingPull connection and eventually recover and receive messages.
  • This would be handled and surfaced as a warning, rather than a thread-killing exception.

This might be the same issue as 2683. This comment, in particular, seems like the solution that I would expect the client library to implement.

Answers to standard questions:

  1. OS type and version
    MacOS Sierra 10.12.6
  2. Python version and virtual environment information python --version
    Python 2.7.10 (running in virtualenv)
  3. google-cloud-python version pip show google-cloud, pip show google-<service> or pip freeze
$ pip show google-cloud
Name: google-cloud
Version: 0.27.0
pip show google-cloud-pubsub
Name: google-cloud-pubsub
Version: 0.28.4
  1. Stacktrace if available
Exception in thread Consumer helper: consume bidirectional stream:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/Users/kir/cloud/env/lib/python2.7/site-packages/google/cloud/pubsub_v1/subscriber/_consumer.py", line 248, in _blocking_consume
    self._policy.on_exception(exc)
  File "/Users/kir/cloud/env/lib/python2.7/site-packages/google/cloud/pubsub_v1/subscriber/policy/thread.py", line 140, in on_exception
    raise exception
_Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, The service was unable to fulfill your request. Please try again. [code=8a75])>
  1. Steps to reproduce
  • I was not able to reproduce this consistently. But it would happen ~1 in 10 times I ran the code.
  1. Code example
import time, datetime, sys
from google.cloud import pubsub_v1 as pubsub

subscription_name = "projects/%s/subscriptions/%s"%(sys.argv[1], sys.argv[2])
sleep_time_ms = 0
try:
    sleep_time_ms = int(sys.argv[3])
except Exception:
    print "Could not parse custom sleep time."
print "Using sleep time %g ms"%sleep_time_ms

def callback(message):
    t = time.time()
    time.sleep(float(sleep_time_ms)/1000)
    print "Message " + message.data + " acked in %g second"%(time.time() - t)
    message.ack()

subscription = pubsub.SubscriberClient().subscribe(subscription_name).open(callback=callback)
time.sleep(10000)
Reacted by Evgeny Medvedev

Activity

Next
  1. theacodes commented on Oct 20, 2017

    @theacodes
    theacodes
    on Oct 20, 2017
    Contributor
    More actions

    Rengerating pubsub to use api_core should solve this, I think.

  2. kir-titievsky commented on Oct 20, 2017

    @kir-titievsky
    kir-titievsky
    on Oct 20, 2017
    Author
    More actions

    How would I do that?

  3. theacodes commented on Oct 20, 2017

    @theacodes
    theacodes
    on Oct 20, 2017
    Contributor
    More actions

    We're working on it. :)

  4. gcbirzan commented on Oct 23, 2017

    @gcbirzan
    gcbirzan
    on Oct 23, 2017
    Contributor
    More actions

    We're able to reproduce this consistently within 1-2 minutes of starting a snippet virtually identical to the one on https://cloud.google.com/pubsub/docs/pull#pubsub-pull-messages-async-python. There are no messages published on the topic. Our stacktrace is a bit different, though:

    Exception in thread Consumer helper: consume bidirectional stream:
    Traceback (most recent call last):
      File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
        self.run()
      File "/usr/lib/python3.6/threading.py", line 864, in run
        self._target(*self._args, **self._kwargs)
      File "/home/gcbirzan/.virtualenvs/pubsub/lib/python3.6/site-packages/google/cloud/pubsub_v1/subscriber/_consumer.py", line 248, in _blocking_consume
        self._policy.on_exception(exc)
      File "/home/gcbirzan/.virtualenvs/pubsub/lib/python3.6/site-packages/google/cloud/pubsub_v1/subscriber/policy/thread.py", line 140, in on_exception
        raise exception
      File "/home/gcbirzan/.virtualenvs/pubsub/lib/python3.6/site-packages/google/cloud/pubsub_v1/subscriber/_consumer.py", line 234, in _blocking_consume
        for response in response_generator:
      File "/home/gcbirzan/.virtualenvs/pubsub/lib/python3.6/site-packages/grpc/_channel.py", line 363, in __next__
        return self._next()
      File "/home/gcbirzan/.virtualenvs/pubsub/lib/python3.6/site-packages/grpc/_channel.py", line 357, in _next
        raise self
    grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, The service was unable to fulfill your request. Please try again. [code=8a75])>
    
    Reacted by Vishnu
  5. thomas-vl commented on Oct 24, 2017

    @thomas-vl
    thomas-vl
    on Oct 24, 2017
    More actions

    Any update about this issue?

  6. anroopak commented on Oct 24, 2017

    @anroopak
    anroopak
    on Oct 24, 2017
    More actions

    Any update about this issue?

  7. a13x6au3r commented on Oct 24, 2017

    @a13x6au3r
    a13x6au3r
    on Oct 24, 2017
    More actions

    Any update about this issue?

  8. murataksoy commented on Oct 25, 2017

    @murataksoy
    murataksoy
    on Oct 25, 2017
    More actions

    @kir-titievsky, the solution you mentioned seems to work at first, but the problem with this approach seems to be that the CPU usage goes up every time the UNAVAILABLE exception is handled this way. Thus, a fix seems to be necessary.

    Reacted by Danny Hermes
  9. lukesneeringer
    added
    api: pubsubIssues related to the Pub/Sub API.
    on Oct 26, 2017
  10. lukesneeringer commented on Oct 26, 2017

    @lukesneeringer
    lukesneeringer
    on Oct 26, 2017
    Contributor
    More actions

    Hey folks,
    I have an update on this issue. :-) I am working on it today.
    As @murataksoy mentioned, it is not just as simple as adding an if line to return None from UNAVAILABLE, because threads are building up. (#3965)

    Hoping to have a fix today or tomorrow.

  11. sss721 commented on Oct 27, 2017

    @sss721
    sss721
    on Oct 27, 2017
    More actions

    Any update on this issue?

  12. ckmvishnu commented on Oct 31, 2017

    @ckmvishnu
    ckmvishnu
    on Oct 31, 2017
    More actions

    Commented out exception raising code. But events are not consistent. I currently have subscriptions for insert/delete/preempt VM operations, But I consistently miss out preempt events.

    My edit was to ignore self._policy.on_exception(exc) in _blocking_consume method.

  13. lukesneeringer commented on Oct 31, 2017

    @lukesneeringer
    lukesneeringer
    on Oct 31, 2017
    Contributor
    More actions

    Any update on this issue?

    Sorry, I forgot to tag this issue. #4265 fixed this, and has been merged. A new version will be cut soon (within a day or two).

  14. lukesneeringer
    closed this as completedon Oct 31, 2017
  15. lukesneeringer commented on Oct 31, 2017

    @lukesneeringer
    lukesneeringer
    on Oct 31, 2017
    Contributor
    More actions

    Wait, sorry, I got confused. I still need to do the api_core integration to properly fix this. Right now the exception is bubbling properly (that is what #4265 did) but not retrying.

    Re-opening, and a fix will be in soon.

  16. 43 remaining items

  17. makrusak commented on Nov 29, 2017

    @makrusak
    makrusak
    on Nov 29, 2017
    More actions

    @dhermes My logs look like: https://pastebin.com/Dn9Lnynb (and so on and so on). As you can see initial request is sending repeatedly each 1.5 minutes.
    Pyhon sample from here, for example: https://cloud.google.com/pubsub/docs/pull.
    I am just using future like this instead of

    while True:
        subscription = subscriber.subscribe(subscription_path, callback=run_combine_process)
        subscription.future.result()
  18. dhermes commented on Nov 30, 2017

    @dhermes
    dhermes
    on Nov 30, 2017
    Contributor
    More actions

    @makrusak I just cut another release https://pypi.org/project/google-cloud-pubsub/0.29.2/. This will at least stop some of the threads that weren't previously being stopped. However, it won't close the bidirectional consumer(s) on failure. You can do that by calling Policy.close() after the future returned from Policy.open() is done().

  19. makrusak commented on Nov 30, 2017

    @makrusak
    makrusak
    on Nov 30, 2017
    More actions

    @dhermes Thanks! I'll validate it today and hope that all critical bugs will be fixed soon.

  20. dhermes commented on Nov 30, 2017

    @dhermes
    dhermes
    on Nov 30, 2017
    Contributor
    More actions

    @makrusak I've definitely traced down at last one place where threads are leaked, but I can't get the CPU usage to spike much more than 3% after running for 300 seconds (which ends up recovering from UNAVAILABLE 3 times, leaving 3 zombie threads).

  21. itamar-resonai commented on Dec 3, 2017

    @itamar-resonai
    itamar-resonai
    on Dec 3, 2017
    More actions

    I've updated from 0.28.4 to 0.29.2, and now I get the following error exactly 90 seconds after the client starts listening:

    E1203 07:05:39.795156557      17 chttp2_transport.c:1005]    Received a GOAWAY with error code ENHANCE_YOUR_CALM and debug data equal to "too_many_pings"
    Exception in thread Thread-ConsumerHelper-ConsumeBidirectionalStream:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
        self.run()
      File "/usr/lib/python2.7/threading.py", line 754, in run
        self.__target(*self.__args, **self.__kwargs)
      File "/usr/local/lib/python2.7/dist-packages/google/cloud/pubsub_v1/subscriber/_consumer.py", line 246, in _blocking_consume
        recover = self._policy.on_exception(exc)
      File "/usr/src/app/cloudapi/pubsub.py", line 28, in on_exception
        code_value = getattr(exc, 'code', lambda: None)()
    TypeError: 'int' object is not callable
    
  22. dhermes commented on Dec 4, 2017

    @dhermes
    dhermes
    on Dec 4, 2017
    Contributor
    More actions

    @itamar-resonai That line is from 0.29.0, not from 0.29.2.

    Maybe there is an issue with your install?

  23. itamar-resonai commented on Dec 4, 2017

    @itamar-resonai
    itamar-resonai
    on Dec 4, 2017
    More actions

    Sorry, my bad.

    It was indeed 0.29.2, but I didn't disable the IgnoreRpcFailureHack policy-workaround, so that what happened...

  24. brianbaquiran commented on May 29, 2018

    @brianbaquiran
    brianbaquiran
    on May 29, 2018
    More actions

    It seems like the error still persists with pubsub 0.35.0. My pip freeze

    google-api-core==1.2.0
    googleapis-common-protos==1.5.3
    google-auth==1.4.1
    google-cloud-core==0.28.1
    google-cloud-error-reporting==0.30.0
    google-cloud-logging==1.6.0
    google-cloud-pubsub==0.35.0
    google-cloud-storage==1.10.0
    google-resumable-media==0.3.1
    grpc-google-iam-v1==0.11.4
    grpcio==1.12.0
    

    I am seeing the traceback:

    Traceback (most recent call last):
     File "/usr/local/lib/python3.5/site-packages/google/api_core/grpc_helpers.py", line 76, in next return six.next(self._wrapped)
     File "/usr/local/lib/python3.5/site-packages/grpc/_channel.py", line 341, in __next__ return self._next()
     File "/usr/local/lib/python3.5/site-packages/grpc/_channel.py", line 335, in _next raise self grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, The service was unable to fulfill your request. Please try again. [code=8a75])>
    

    In case it matters, I'm running my code on GKE.

  25. tseaver
    added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on May 29, 2018
  26. tseaver
    assigned
    theacodes
    and unassigned
    lukesneeringer
    on May 29, 2018
  27. brianbaquiran commented on May 30, 2018

    @brianbaquiran
    brianbaquiran
    on May 30, 2018
    More actions

    Now, testing with 0.35.1, I am seeing the same error. Cutting-and-pasting from Stackdriver logs:

    RPC termination has signaled streaming pull manager shutdown.
    Stopping consumer.
    Thread-ConsumeBidirectionalStream caught unexpected exception cannot join current thread and will exit.
    Traceback (most recent call last):
      File "/usr/local/lib/python3.5/site-packages/google/api_core/grpc_helpers.py", line 76, in next
        return six.next(self._wrapped)
      File "/usr/local/lib/python3.5/site-packages/grpc/_channel.py", line 341, in __next__
        return self._next()
      File "/usr/local/lib/python3.5/site-packages/grpc/_channel.py", line 335, in _next
        raise self
    grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, The service was unable to fulfill your request. Please try again. [code=8a75])>
    
    The above exception was the direct cause of the following exception:
    Traceback (most recent call last):
      File "/usr/local/lib/python3.5/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/bidi.py", line 369, in _recoverable
        return method(*args, **kwargs)
      File "/usr/local/lib/python3.5/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/bidi.py", line 258, in recv
        return next(self.call)
      File "/usr/local/lib/python3.5/site-packages/google/api_core/grpc_helpers.py", line 78, in next
        six.raise_from(exceptions.from_grpc_error(exc), exc)
      File "<string>", line 3, in raise_from
    google.api_core.exceptions.ServiceUnavailable: 503 The service was unable to fulfill your request. Please try again. [code=8a75]
    
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
      File "/usr/local/lib/python3.5/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/bidi.py", line 456, in _thread_main
        response = self._bidi_rpc.recv()
      File "/usr/local/lib/python3.5/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/bidi.py", line 382, in recv
        super(ResumableBidiRpc, self).recv)
      File "/usr/local/lib/python3.5/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/bidi.py", line 373, in _recoverable
        self._finalize(exc)
      File "/usr/local/lib/python3.5/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/bidi.py", line 323, in _finalize
        callback(result)
      File "/usr/local/lib/python3.5/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py", line 424, in _on_rpc_done
        self.close(reason=future)
      File "/usr/local/lib/python3.5/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py", line 321, in close
        self._consumer.stop()
      File "/usr/local/lib/python3.5/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/bidi.py", line 493, in stop
        self._thread.join()
      File "/usr/local/lib/python3.5/threading.py", line 1051, in join
        raise RuntimeError("cannot join current thread")
    RuntimeError: cannot join current thread
    
    Thread-ConsumeBidirectionalStream exiting
    Cleanly exiting request generator.
    Thread-LeaseMaintainer exiting.
    

    My relevant pip freeze:

    google-api-core==1.2.0
    google-auth==1.4.2
    google-cloud-core==0.28.1
    google-cloud-error-reporting==0.30.0
    google-cloud-logging==1.6.0
    google-cloud-pubsub==0.35.1
    google-cloud-storage==1.10.0
    google-resumable-media==0.3.1
    googleapis-common-protos==1.5.3
    grpc-google-iam-v1==0.11.4
    grpcio==1.12.0
    
  28. theacodes commented on May 30, 2018

    @theacodes
    theacodes
    on May 30, 2018
    Contributor
    More actions

    Thanks, @brianbaquiran, let's track this over at #4234.

  29. jakeczyz commented on Apr 6, 2019

    @jakeczyz
    jakeczyz
    on Apr 6, 2019
    More actions

    @theacodes , the issue you linked to in the comment above is this self-same issue. :) Is there another issue you meant to link that discusses catching internal-thread pubsub exceptions? I haven't been able to find a satisfactory answer. Thanks.

    https://stackoverflow.com/q/55552606/379037

  30. parthea
    added a commit that references this issue on Mar 2, 2026

    PubSub: Making `thread.Policy.on_exception` more robust. (#4444)

    b8b01bb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @theacodes
    theacodes

Labels

api: pubsubIssues related to the Pub/Sub API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to 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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.