Skip to content

Thread-ConsumeBidirectionalStream caught unexpected exception 'generator' object has no attribute 'add_done_callback' and will exit. #1180

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

Open
mharoonkwentra opened this issue Jul 5, 2022 · 9 comments
Labels
bug Something isn't working

Comments

@mharoonkwentra
Copy link

mharoonkwentra commented Jul 5, 2022

Notes
We are trying to use Opentelemetry to instrument grpc to get traces of functions. We observed this error on local once, and we couldn't reproduce it again, but it's always on production server. Furthermore, we are using GCP monitoring suite (stack drive) to check traces.

Environment:
Django==3.2.6
Python==3.7

grpcio-tools==1.32.0
grpcio==1.33.2

opentelemetry-api==1.4.1
opentelemetry-sdk==1.4.1
opentelemetry-instrumentation-grpc==0.23b2

Instrumentation code:
set_global_textmap(CloudTraceFormatPropagator())
# sampling sends a portion of generated spans based on a 1/X population size
sample_rate = int(os.getenv('SAMPLE_RATE', '1'))
sampler = TraceIdRatioBased(1 / sample_rate)
tracer_provider = TracerProvider(sampler=sampler)
cloud_trace_exporter = CloudTraceSpanExporter()
tracer_provider.add_span_processor(SimpleSpanProcessor(cloud_trace_exporter))
trace.set_tracer_provider(tracer_provider)
tracer = trace.get_tracer(name)
GrpcInstrumentorClient().instrument() # when commented error isn't reproduced
except (ValueError, NotImplementedError, DefaultCredentialsError) as exc:
print(exc) # Handle errors here

The error
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/google/api_core/bidi.py", line 637, in _thread_main
self._bidi_rpc.open()
File "/usr/local/lib/python3.7/site-packages/google/api_core/bidi.py", line 287, in open
call._wrapped.add_done_callback(self._on_call_done)
AttributeError: 'generator' object has no attribute 'add_done_callback'

@AkselAllas
Copy link

I have the same issue. Not using django. Maybe a grpcio issue?

@drice
Copy link

drice commented Oct 2, 2024

I've found this occurs when using StreamingPullManager from google-cloud-pubsub, as in this sample:

import google.cloud.pubsub_v1 as pubsub_v1
from opentelemetry.instrumentation.grpc import GrpcInstrumentorClient


def sample_streaming_pull():
    # Create a client
    client = pubsub_v1.SubscriberClient()
    future = client.subscribe(
        subscription="<your pubsub subscription ID>",
        callback=print
    )
    with client:
        future.result()


if __name__ == "__main__":
    client = GrpcInstrumentorClient()
    client.instrument()

    sample_streaming_pull()

I think the issue is potentially here

Instead of checking for only is_server_stream:

        if client_info.is_server_stream:
            return self._intercept_server_stream(
                request_or_iterator, metadata, client_info, invoker
            )

should this check that it's not bidirectional?

if client_info.is_server_stream and not client_info.is_client_stream:

It looks like from the referenced PRs that #1583 would potentially resolve.

@jaydeerossi
Copy link

I'm having this same issue right now.

@pickfire
Copy link

pickfire commented Dec 4, 2024

Same issue with google ads

@arjunraman-ant
Copy link

@drice I had the same issue with Pub/Sub recently. The issue was SubscriberClient is NOT thread safe, and I was sharing the client. Creating a SubscriberClient per thread fixed it. There is no documentation of this in any of the GCP docs unfortunately.

@ElliotSteene-Ki
Copy link

Also having this issue:

Environment:
FastAPI==0.109.2
Python==3.11

grpcio==1.70.0

opentelemetry-api==1.30.0
opentelemetry-sdk==1.30.0
opentelemetry-instrumentation-grpc==0.51b0

@arjunraman-ant - do you have any details about how these were run in separate threads?

@robert-lore
Copy link

Having same issue.

@bartek-kossak-flyr
Copy link

me too

@robert-lore
Copy link

@drice I had the same issue with Pub/Sub recently. The issue was SubscriberClient is NOT thread safe, and I was sharing the client. Creating a SubscriberClient per thread fixed it. There is no documentation of this in any of the GCP docs unfortunately.

Could you post your solution? It may help us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants