aio-libs / aio-libs/aiohttp

Make sure that client response life cycle is shorter than client session

Đang mở
#3,772 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
client enhancement
Ngôn ngữ chính
Python
Star
16.5k
Fork
2.4k
Merge trung bình
17 giờ 22 phút
Pull request đã merge (30 ngày)
212

Mô tả

I observed a code like this on stack overflow:
```python
async def fetch(url, data):
async with ClientSession() as session:
response = await session.post(url, data=data)

return response
```
The function is really wrong (while it may work for short response body).
The problem is: a session is destroyed *before* response destruction.
If the response did not come as short data and IO is needed for `await response.read()` and family the code fails with a very cryptic exception.

`ClientResponse` should have a weak reference to `ClientSession`. When the session is gone weakref callback should raise an exception.

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

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

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.