aio-libs / aio-libs/aiohttp

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

オープン
#3,772 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
client enhancement
主要言語
Python
スター
16.5k
フォーク
2.4k
平均マージ
17時間 22分
マージ済み PR(30日)
212

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。