AsyncioIntegration hides an eager task factory from anyio, which breaks anyio task groups
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- observability-sre
Direzione di ricerca
Start in sentry_sdk/integrations/asyncio.py at AsyncioIntegration and _sentry_task_factory, then reproduce the failure with Python 3.12+, anyio 4.8+, and the example in the issue. Check the eager-task-factory handling against asyncio.create_eager_task_factory(). Done means anyio recognizes the installed factory, task groups exit normally, and existing span behavior remains intact.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
How do you use Sentry?
Sentry Saas (sentry.io)
Version
2.70.0
Steps to Reproduce
Python 3.12 or later, anyio 4.8 or later.
import asyncio
import anyio
import sentry_sdk
from sentry_sdk.integrations.asyncio import AsyncioIntegration
async def child(event):
await event.wait()
async def main():
asyncio.get_running_loop().set_task_factory(asyncio.eager_task_factory)
sentry_sdk.init(integrations=[AsyncioIntegration()])
async with anyio.create_task_group() as tg:
tg.start_soon(child, anyio.Event())
await anyio.sleep(0.01)
tg.cancel_scope.cancel()
asyncio.run(main())
Expected Result
The task group exits normally, as it does without AsyncioIntegration.
Actual Result
ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
RuntimeError: Attempted to exit a cancel scope that isn't the current tasks's current cancel scope
Cause
anyio starts the children of a task group non-eagerly, whatever the loop's task factory.
To do that it has to recognise an eager task factory, and asyncio offers no public way to ask.
anyio compares factory.__code__ with asyncio.eager_task_factory.__code__, which every factory returned by asyncio.create_eager_task_factory() shares, and then calls the task constructor from the factory's closure.
AsyncioIntegration replaces the loop's task factory with _sentry_task_factory, a plain function that calls the original.
Its code object is its own, so anyio takes it for an ordinary factory, the child starts eagerly inside create_task(), and anyio's bookkeeping for the task is written after the task has already run.
Proposed fix
When the original factory is an eager one, install a factory built with asyncio.create_eager_task_factory() and wrap the coroutine in its task constructor.
Tasks stay eager, spans are created as before, and anyio recognises the factory.
I have a patch with tests and can open a PR if this approach is acceptable.
- Lingua principale
- Python
- Stelle
- 2.2k
- Fork
- 672
- Merge medio
- 22h 8m
- PR unite (30g)
- 228
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di getsentry/sentry-python
-
Python Task
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
getsentry/sentry-python#7668 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Python Task
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
getsentry/sentry-python#7663 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Python Task
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
getsentry/sentry-python#7652 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Remove send_default_pii from httpxForse già presa @sentrivana l’ha presa 3 giorni fa. ApertaPython
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
getsentry/sentry-python#7653 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Remove send_default_pii from httpx2Forse già presa @sentrivana l’ha presa 3 giorni fa. ApertaPython
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
getsentry/sentry-python#7654 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di getsentry/sentry-python
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
PedestrianDynamics/pyFDS-Evac#199 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
521xueweihan/HelloGitHub#3790 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
sandialabs/atlas-ui-3#978 ·
I maintainer di solito rispondono entro 1 giorno
-
area: tests perceived difficulty: 2
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Nitjsefnie-Harness-Commons/daedalus#1255 ·
I maintainer di solito rispondono entro 1 giorno
-
hf-audiolm-qwen: `generate_until` hardcodes `.to("cuda")` and aborts on non-CUDA acceleratorsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
EleutherAI/lm-evaluation-harness#4256 ·
I maintainer di solito rispondono entro 1 giorno