MagicStack / MagicStack/uvloop

sys.exit(...) exception swallowed by uvloop

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

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

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

  • Python version:
    3.11.9

  • Platform:
    MacOS 14.5 (Sonoma)
    mamba 1.5.8
    conda 24.5.0

  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?:
    Not yet

  • Does uvloop behave differently from vanilla asyncio? How?:
    I have never had this bug with vanilla asyncio

If a sys.exit(...) call is made while uvloop is being used in coroutines (in my case, through aiohttp crawling of web URLs), uvloop may catch the SystemExit exception, and not let it bubble as a SystemExit to the top of the application. Instead, it logs this at the ERROR level:

2024-07-26 06:25:06,802 ERROR asyncio Fatal error on transport TCPTransport
protocol: <uvloop.loop.SSLProtocol object at 0x16b54de80>
transport: <TCPTransport closed=False reading=False 0x1693bfff0>
Traceback (most recent call last):
  File "uvloop/handles/stream.pyx", line 1007, in uvloop.loop.__uv_stream_buffered_on_read
  File "uvloop/loop.pyx", line 109, in uvloop.loop.run_in_context1
  File "uvloop/sslproto.pyx", line 382, in uvloop.loop.SSLProtocol.buffer_updated
  File "uvloop/sslproto.pyx", line 711, in uvloop.loop.SSLProtocol._do_read
  File "uvloop/sslproto.pyx", line 776, in uvloop.loop.SSLProtocol._do_read__copied
  File "/opt/homebrew/Caskroom/miniforge/base/envs/work/lib/python3.11/ssl.py", line 912, in read
    def read(self, len=1024, buffer=None):
    
  File "/Users/dmoklaf/Local/metax/python_libraries/application.py", line 171, in _exit
    sys.exit(code)
SystemExit: 1

Indeed, a quick look at the uvloop code shows that it logs the SystemExit exception, as SystemExit does not subclass OSError:
https://github.com/MagicStack/uvloop/blob/6c770dc3fbdd281d15c2ad46588c139696f9269c/uvloop/handles/basetransport.pyx#L40
PS: there also seems to be other _fatal_error implementations in uvloop, I am not completely sure if these other places do not suffer from the same issue

And it also swallows the SystemExit exception, instead of propagating it upward as requested by the Python specification.

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 tại uvloop/handles/basetransport.pyx, quanh phần triển khai _fatal_error được liên kết, và tái hiện hành vi SystemExit đã được báo cáo trong uvloop. Xem lại các phần triển khai _fatal_error khác được đề cập trong issue, sau đó xác minh rằng SystemExit được truyền lên ứng dụng thay vì bị ghi log và nuốt mất.

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
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
38/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.