UDPTransport.abort() with a queued datagram reports a fatal write error and a resume_writing() AttributeError
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 68/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
- 領域
- networking
調査の方向性
Start by reproducing the issue with the provided script, then trace UDPTransport.abort() and UVBaseTransport._maybe_resume_protocol to see how queued-send cancellation and protocol detachment interact. Compare the exception-handler output with vanilla asyncio; done means abort discards the queued datagram without reporting either error, while connection_lost(None) still occurs.
索引モデルが issue の本文から書いたものです。
説明
- uvloop version: 0.23.0 (also 0.22.1)
- Python version: 3.12.3
- Platform: Linux (x86_64, glibc 2.39)
- Can you reproduce the bug with
PYTHONASYNCIODEBUGin env?: Yes - Does uvloop behave differently from vanilla asyncio? How?: Yes. With vanilla asyncio,
abort()silently discards the queued datagram and callsconnection_lost(None). With uvloop,connection_lost(None)is called too, but two errors are also passed to the loop's exception handler.
Calling abort() on a UDPTransport while a datagram is still queued (because the OS refused it with EAGAIN) reports two errors to the loop's exception handler:
Fatal error on transport UDPTransport (Fatal write error on datagram transport), withexception=CancelledError(). The queued send is cancelled because we aborted, so this is not an error.protocol.resume_writing() failed, withAttributeError("'NoneType' object has no attribute 'resume_writing'"), raised fromUVBaseTransport._maybe_resume_protocolafter the protocol has already been detached.
A UNIX datagram socket is used to make the OS refuse datagrams, because UDP on loopback never exerts back-pressure. The peer never reads, so the send buffer fills up.
import asyncio
import socket
import sys
import tempfile
import uvloop
class Protocol(asyncio.DatagramProtocol):
def connection_made(self, transport):
transport.set_write_buffer_limits(0)
def connection_lost(self, exc):
print("connection_lost", exc)
async def main():
loop = asyncio.get_running_loop()
errors = []
loop.set_exception_handler(lambda loop, context: errors.append(context))
path = f"{tempfile.mkdtemp()}/peer.sock"
peer = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
peer.bind(path) # never read from
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
sock.connect(path)
sock.setblocking(False)
transport, _ = await loop.create_datagram_endpoint(Protocol, sock=sock)
# Send until the OS refuses a datagram and the transport has to queue it
while not transport.get_write_buffer_size():
transport.sendto(b"x" * 64)
transport.abort()
await asyncio.sleep(0.1)
for context in errors:
print("exception handler:", context["message"], repr(context.get("exception")))
if sys.argv[1:] == ["uvloop"]:
uvloop.run(main())
else:
asyncio.run(main())
Output with python repro.py:
connection_lost None
Output with python repro.py uvloop:
connection_lost None
exception handler: Fatal error on transport UDPTransport (Fatal write error on datagram transport) CancelledError()
exception handler: protocol.resume_writing() failed AttributeError("'NoneType' object has no attribute 'resume_writing'")
Expected: the same as vanilla asyncio, i.e. the queued datagram is silently discarded and nothing is reported to the exception handler.
Found via anyio, whose UDP socket aclose() aborts the transport.
- 主要言語
- Cython
- スター
- 11.9k
- フォーク
- 616
- 平均マージ
- 4時間 43分
- マージ済み PR(30日)
- 3
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
MagicStack/uvloop のほかの issue
-
uv 1.53.0 fix対応中かも @fantix が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
MagicStack/uvloop#774 · コメント 1 件 · リアクション 1 件 ·
-
License not clearオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
MagicStack/uvloop#759 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
MagicStack/uvloop#741 · リアクション 2 件 ·
-
`asyncio.get_event_loop` raises error instead of spawning new loop when no loop is running.対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
MagicStack/uvloop#702 · コメント 8 件 · リアクション 9 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
MagicStack/uvloop#773 ·
MagicStack/uvloop の issue をすべて見る
似ている issue
-
alignment blocked
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
btclib-org/btclib-node#1770 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area/security
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
agent-substrate/substrate#2276 ·
メンテナーはふだん 1 日以内に返信
-
triage/needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
praxis-proxy/praxis#1357 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
v2fly/domain-list-community#4127 ·
メンテナーはふだん 2 日以内に返信