MagicStack / MagicStack/uvloop

set_exception_handler is not handling exception as expected.

未关闭
#360 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,将 uvloop/loop.pyx 中 run_until_complete 附近的代码(第 1454 行)与 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 摘要。