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 分钟
- 30 天内合并 PR
- 3
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MagicStack/uvloop 的其他 Issue
-
uv 1.53.0 fix可能已有人在做 @fantix 于 1 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 85/100
MagicStack/uvloop#774 · 1 条评论 · 1 个 reaction ·
-
难度 2/5 1-3 小时 新手友好度 68/100
MagicStack/uvloop#759 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
MagicStack/uvloop#741 · 2 个 reaction ·
-
`asyncio.get_event_loop` raises error instead of spawning new loop when no loop is running.可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
MagicStack/uvloop#702 · 8 条评论 · 9 个 reaction ·
-
难度 5/5 一周以上 新手友好度 25/100
MagicStack/uvloop#773 ·
查看 MagicStack/uvloop 的全部 Issue
相似的 Issue
-
Aborting a request that waits for a socket destroys that socket under a later request (socket hang up)可能已有人在做 @vvo 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
ClickHouse/clickhouse-js#1040 ·
维护者通常 7 天内回复
-
bug upstream
难度 2/5 1-3 小时 新手友好度 85/100
Sendspin/sendspin-dotnet#321 ·
维护者通常 1 天内回复
-
withMaxHeaderSize is not applied to HTTP/2 since h2c support in 0.7.2 (431 Request Header Fields Too Large)可能已有人在做 @rbos-dhl 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
http4s/http4s-netty#1028 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
v2fly/v2ray-core#3842 ·
维护者通常 1 天内回复
-
bug needs triage tcp
难度 2/5 1-3 小时 新手友好度 78/100
project-chip/connectedhomeip#74644 ·
维护者通常 1 天内回复