AsyncioIntegration hides an eager task factory from anyio, which breaks anyio task groups
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 68/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 2.2k
- フォーク
- 672
- 平均マージ
- 22時間 8分
- マージ済み PR(30日)
- 228
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
getsentry/sentry-python のほかの issue
-
Python Task
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
getsentry/sentry-python#7668 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Python Task
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
getsentry/sentry-python#7663 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Python Task
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
getsentry/sentry-python#7652 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Python
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
getsentry/sentry-python#7653 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Python
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
getsentry/sentry-python#7654 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
getsentry/sentry-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
solana-foundation/pay-kit#341 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nasa/python_cmr#123 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
EleutherAI/lm-evaluation-harness#4243 ·
メンテナーはふだん 1 日以内に返信
-
area: dashboard bug perceived difficulty: 3
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
Nitjsefnie-Harness-Commons/daedalus#1179 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
cusp-ai-oss/tojax#17 ·