MagicStack / MagicStack/uvloop
Server.serve_forever() isn't cancelled when Server.close() is called
まだ誰も着手していません。
- 主要言語
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、Lib/asyncio/base_events.py の341~344行付近でリンクされている CPython の実装と uvloop のサーバー動作を比較し、Server.serve_forever() と Server.close() に焦点を当てます。提供されている SIGTERM の例で問題を再現し、サーバーを閉じると serve_forever() が asyncio.CancelledError を発生させ、終了前に「Shutting down」と出力することを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend, networking
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100