Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP response not released with raise_for_status=True #3364

Closed
Grendel7 opened this issue Oct 26, 2018 · 3 comments
Closed

HTTP response not released with raise_for_status=True #3364

Grendel7 opened this issue Oct 26, 2018 · 3 comments

Comments

@Grendel7
Copy link
Contributor

Long story short

When using ClientSession with raise_for_status=True, HTTP responses are not released. This means the related TCP connection will remain in CLOSE_WAIT state indefinitely, when the called server returns an error status code and a large body. Eventually, these waiting connections will hit the connection limit and cause timeout errors on ALL open connections.

Expected behaviour

When using Client Session with raise_for_status=True, TCP connections are released properly and they are either closed or reused (depending on keep alive configuration).

Actual behaviour

When using Client Session with raise_for_status=True, the TCP connections

Steps to reproduce

client.py

from aiohttp import ClientSession, ClientResponseError
import asyncio


async def send_request():
    client = ClientSession(raise_for_status=True)

    try:
        async with client.get('http://hansadema.com/404.php') as response:
            print('Received good status %d' % response.status)
    except ClientResponseError as e:
        print('Received bad status %d' % e.status)


loop = asyncio.get_event_loop()
asyncio.ensure_future(send_request())
loop.run_forever()

Dockerfile

FROM python:3.6-slim

COPY . /usr/src/app
RUN pip install aiohttp

CMD python /usr/src/app/client.py

Commands:

$ docker build -t aiohttp-test .
$ docker run --rm --name aiohttp-test aiohttp-test
# Linux command to check open connections
$ sudo nsenter -t (docker inspect -f '{{.State.Pid}}' "aiohttp-test") -n ss --numeric --tcp

Your environment

aiohttp 3.4.4
Python 3.6.6
Debian 9.5

@aio-libs-bot
Copy link

GitMate.io thinks the contributor most likely able to help you is @asvetlov.

Possibly related issues are #2782 (Unsolicited response received on idle HTTP channel starting with "\r\n"; err=), #3248 (history tuple on ClientResponseError empty with raise_for_status() or ClientSession(raise_for_status=True)), #852 (Http client HEAD request failed to release), #33 (HTTPS Support), and #117 (HTTP GET + compress=True = 501).

@asvetlov
Copy link
Member

asvetlov commented Dec 1, 2018

Fixed by #3365

@asvetlov asvetlov closed this as completed Dec 1, 2018
@lock
Copy link

lock bot commented Dec 1, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Dec 1, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Dec 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants