MagicStack / MagicStack/uvloop

set_exception_handler is not handling exception as expected.

オープン
#360 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

need more info
主要言語
Cython
スター
11.9k
フォーク
616
PR マージ指標
30日以内にマージされた PR はありません

説明

* **uvloop version**: 0.14.0
* **Python version**: 3.6.9
* **Platform**: Linux c965e3d4adf2 5.3.0-1032-gcp #34~18.04.1-Ubuntu SMP
* **Can you reproduce the bug with `PYTHONASYNCIODEBUG` in env?**: yes
* **Does uvloop behave differently from vanilla asyncio? How?**:

Yes asyncio default loop catches `TimeoutError: [Errno 110] Connection timed out` whereas uvloop closes the loop and throws `RuntimeError: Event loop stopped before Future completed.`

I ran across this bug when dealing with websockets (you could see the issue - https://github.com/aaugustin/websockets/issues/823)

To log this error :
```
def handle_async_exception(loop, ctx):
logger.error("Loop error occured", ctx=ctx)
loop = asyncio.get_event_loop()
loop.set_exception_handler(handle_async_exception)
```

Python websockets throw a `TimeoutError` when a client is not found in a certain time limit (for ping/ pongs). In asyncio, the error is bubbled to `set_exception_handler`, and I could log it there as expected. However in uvloop, instead of having the exception being bubbled to exception_handler, it shuts down the loop. I get the following error:

```
Process Process-9:
Traceback (most recent call last):
File "/usr/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "/home/streaming/app/emitter_app/emitter.py", line 60, in start_emitter
loop.run_until_complete(asyncio.gather(server.serve(), push_payload(queue)))
File "uvloop/loop.pyx", line 1454, in uvloop.loop.Loop.run_until_complete
RuntimeError: Event loop stopped before Future completed.
```

Thanks for your time! Appreciate such a neat package to make asyncio faster in python.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、run_until_complete(1454 行目)付近の uvloop/loop.pyx を、vanilla asyncio における set_exception_handler の処理と比較します。PYTHONASYNCIODEBUG を有効にした Python 3.6.9 で websockets のタイムアウトシナリオを再現します。TimeoutError が設定された例外ハンドラーに到達し、ループが予期せず停止しなければ完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend, networking
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。