aio-libs / aio-libs/aiohttp

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

Abierto
#3,772 0 comentarios 0 reacciones 0 asignados Ver en GitHub
client enhancement
Lenguaje dominante
Python
Estrellas
16.5k
Forks
2.4k
Merge medio
17 h 22 min
PR fusionados (30 d)
212

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.