AsyncioIntegration hides an eager task factory from anyio, which breaks anyio task groups
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 68/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- python
- Domaine
- observability-sre
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Python
- Étoiles
- 2.2k
- Forks
- 672
- Merge moyen
- 22 h 8 min
- PR mergées (30 j)
- 228
Préparer son environnement
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de getsentry/sentry-python
-
Python Task
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
getsentry/sentry-python#7668 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Remove send_default_pii from rayOuvertePython Task
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
getsentry/sentry-python#7663 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Python Task
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
getsentry/sentry-python#7652 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Remove send_default_pii from httpxPeut-être pris @sentrivana l’a pris il y a 3 jours. OuvertePython
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
getsentry/sentry-python#7653 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Remove send_default_pii from httpx2Peut-être pris @sentrivana l’a pris il y a 3 jours. OuvertePython
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
getsentry/sentry-python#7654 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de getsentry/sentry-python
Issues similaires
-
needs triage
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
openvinotoolkit/openvino_notebooks#3665 ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
Les mainteneurs répondent en général sous 1 jour
-
docs
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
Les mainteneurs répondent en général sous 1 jour
-
benchmark-gap
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour