MagicStack / MagicStack/uvloop

set_exception_handler is not handling exception as expected.

Đang mở
#360 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

need more info
Ngôn ngữ chính
Cython
Star
11.9k
Fork
616
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

  • 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.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách so sánh uvloop/loop.pyx xung quanh run_until_complete (dòng 1454) với cách vanilla asyncio xử lý set_exception_handler. Tái hiện kịch bản timeout của websockets trên Python 3.6.9 với PYTHONASYNCIODEBUG được bật; được xem là hoàn tất khi TimeoutError đến được trình xử lý ngoại lệ đã cấu hình mà không làm dừng loop một cách bất ngờ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
backend, networking
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.