MagicStack / MagicStack/uvloop
Server.serve_forever() isn't cancelled when Server.close() is called
还没有人认领这个 Issue。
- 主要语言
- Cython
- 星标
- 11.9k
- 派生
- 616
- PR 合并指标
- 30 天内没有已合并 PR
描述
- uvloop version: 0.19.0
- Python version: 3.10.12 (3.10.12-1~22.04.3)
- Platform: Ubuntu 22.04.4
- Can you reproduce the bug with
PYTHONASYNCIODEBUGin env?: Yes - Does uvloop behave differently from vanilla asyncio? How?: Yes, described below.
With stock asyncio, after awaiting on Server.serve_forever(), calling Server.close() causes the await statement to throw CancelledError. With uvloop's implementation, the listening socket is correctly closed, however the await statement blocks indefinitely.
Example:
async def run_server():
async with await asyncio.start_server(lambda r,w: w.close(), '127.0.0.1', 8080) as server:
server.get_loop().add_signal_handler(15, lambda: server.close())
try:
await server.serve_forever()
except asyncio.CancelledError:
print('Shutting down')
uvloop.run(run_server())
The uvloop version closes the listening socket in response to SIGTERM, but never exits. The stock version prints Shutting down and exits.
Here's the CPython source where this is implemented:
https://github.com/python/cpython/blob/v3.8.18/Lib/asyncio/base_events.py#L341-L344
Thanks for taking a look!
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,将 uvloop 的服务器行为与 Lib/asyncio/base_events.py 中第 341–344 行附近链接的 CPython 实现进行比较,重点关注 Server.serve_forever() 和 Server.close()。使用提供的 SIGTERM 示例重现该问题,并确认关闭服务器会导致 serve_forever() 引发 asyncio.CancelledError,并在退出前打印“Shutting down”。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend, networking
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100