MagicStack / MagicStack/asyncpg
asyncpg __del__ methods call asyncio APIs directly, which isn't guaranteed to work and indeed, doesn't work
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 8.1k
- Fork
- 468
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
asyncpg has several __del__ methods that call into asyncio APIs. But... you can't safely call into asyncio APIs from a __del__ method, because __del__ methods can be run in arbitrary threads, or at arbitrary moments when the loop's internal data structures are in an inconsistent state.
Discovered here: https://github.com/python-trio/trio-asyncio/issues/44
Looking at the traceback in that issue, I suspect that the reason this hasn't been noticed before is that the __del__ method ultimately ends up calling loop.call_soon(...). And if you do that from another thread, then with regular asyncio, things will mostly seem to work – it won't actually wake up the loop the way call_soon_threadsafe would, but if the loop is still running then it will eventually get run, and the default call_soon will not explode or otherwise notice if it's called from the wrong thread. But in that issue, someone's using asyncpg with an alternative asyncio loop that fails when call_soon is called from the wrong thread, and this breaks asyncpg.
I guess asyncpg should go through all its __del__ methods and wrap them in a loop.call_soon_threadsafe?
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
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- 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 lập danh mục các phương thức del của asyncpg và các đường dẫn loop.call_soon liên quan đến issue Trio được liên kết. Kiểm tra từng đường dẫn dọn dẹp dựa trên các mối lo ngại về thread safety và trạng thái loop được mô tả ở đó. Công việc được xem là hoàn tất khi hành vi dọn dẹp bị ảnh hưởng hoạt động với các triển khai loop asyncio thay thế mà không thực hiện các lệnh gọi trực tiếp không an toàn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- postgresql, python
- Lĩnh vực
- databases
- 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