-
Notifications
You must be signed in to change notification settings - Fork 413
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
Unexpected Cancellation propagation when using sse-starlette, fastapi, uvloop, and ...gevent? #10550
Comments
Additional weirdness:
|
|
Ah I see now: As part of module cleanup in sitecustomize So some Qs:
|
and of course if I just edit sitecustomize.py (for fun) to remove gevent from MODULE_REQUIRES CLEANUP it also works fine. cool. |
Same issue here, we have Gevent installed which we use with celery for the pool. The codebase between FastAPI and Celery is shared. |
Same issue here with our FastAPI application. Removing |
Summary of problem
TL;DR:
errors
, since they are CancelledErrors.gevent
from my venv, I see no errors.To spare you all the travesty of seeing the giant pile of spaghetti that is my production application, I have managed a smaller reproduction case that I hope helps you.
I'd love to keep gevent installed and either have this bug fixed, or just not instrument gevent in this application; I'm not intending to use gevent at all (I'm supposed to be using asyncio / anyio in fastapi..)
Which version of dd-trace-py are you using?
ddtrace-2.11.3
Which version of pip are you using?
23.0.1
Which libraries and their versions are you using?
`pip freeze`
annotated-types==0.7.0 anyio==3.7.1 bytecode==0.15.1 certifi==2024.8.30 click==8.1.7 ddtrace==2.11.3 Deprecated==1.2.14 distro==1.9.0 envier==0.5.2 exceptiongroup==1.2.2 fastapi==0.104.1 gevent==24.2.1 greenlet==3.0.3 gunicorn==21.2.0 h11==0.14.0 httpcore==1.0.5 httptools==0.6.1 httpx==0.27.2 idna==3.8 importlib_metadata==8.4.0 openai==1.1.1 opentelemetry-api==1.27.0 packaging==24.1 protobuf==5.28.0 pydantic==2.9.0 pydantic_core==2.23.2 python-dotenv==1.0.1 PyYAML==6.0.2 sniffio==1.3.1 sse-starlette==1.6.5 starlette==0.27.0 tqdm==4.66.5 typing_extensions==4.12.2 tzdata==2024.1 uv==0.2.24 uvicorn==0.24.0.post1 uvloop==0.20.0 watchfiles==0.24.0 websockets==13.0.1 wrapt==1.16.0 xmltodict==0.13.0 zipp==3.20.1 zope.event==5.0 zope.interface==7.0.3How can we reproduce your problem?
I am on py3.10
I created a venv, installed the above packages
My reproducer is:
What is the result that you get?
I open two terminals. One I use to run my reproducer:
ddtrace-run python dd_test.py
The second I use to curl the foo endpoint, we just throw the result away (it doesn't matter.)
curl localhost:9005/foo &>/dev/null
However, this triggers some odd cancellation exception:
Some additional context:
sse-starlette uses a task-group in its call function to basically terminate event streaming if
one of many
things happens. You can see this behavior here:Cancellation of this task-group is expected. However somehow something teh tracer is doing when gevent is installed causes this Cancellation propagation. I have not yet waddled through the gevent internal traces.
What is the result that you expected?
(small_repro) (me):~/small_repro$ ddtrace-run python dd_test.py
INFO: Started server process [1981883]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:9005 (Press CTRL+C to quit)
INFO: 127.0.0.1:49796 - "GET /foo HTTP/1.1" 200 OK
The text was updated successfully, but these errors were encountered: