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

Session not closed in aiohttp.request after exception #3628

Closed
fried-sausage opened this issue Feb 27, 2019 · 2 comments

Comments

@fried-sausage
Copy link
Contributor

commented Feb 27, 2019

Long story short

subj
First I get ClientConnectorError (connection-related errors are expected in my application), after that i see Unclosed client session warning.

Expected behaviour

ClientSession, created inside aiohttp.request, is closed after programm leaves async with block.

Actual behaviour

ClientSession is not closed.

Steps to reproduce

import asyncio
import aiohttp


async def main():
    async with aiohttp.request("GET", "http://127.0.0.1:8080") as resp:
        pass


loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(main())
finally:
    loop.close()

Your environment

aiohttp 3.5.4
python 3.5
debian stretch

Why use aiohttp.request at all, opening new connection for every request is bad

I need to open new connection anyway:

  1. server i talk to does not support keep-alive
  2. i programm client that runs on a moving device using wifi network so connection failures are expected
@aio-libs-bot

This comment has been minimized.

Copy link
Collaborator

commented Feb 27, 2019

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

Possibly related issues are #2920 (AIOHttp failing after some requests), #3523 (aiohttp not forwarding cookies with Session requests), #3031 (aiohttp request exceptions can't be caught sometimes when encountering bad http message), #3296 (aiohttp client session. it doesn't close a connection after keepalive_timeout), and #1403 ([QUESTION] aiohttp.ClientSession.request('GET') issue).

@aio-libs-bot aio-libs-bot added the bug label Feb 27, 2019

asvetlov added a commit that referenced this issue Jul 19, 2019
asvetlov added a commit that referenced this issue Jul 19, 2019
[3.5] Close session on error in aiohttp.request (#3628) (#3640)
(cherry picked from commit 20bfadc)

Co-authored-by: Robert Nikolich <rob-joy@yandex.ru>
@asvetlov

This comment has been minimized.

Copy link
Member

commented Jul 19, 2019

Fixed by #3640

@asvetlov asvetlov closed this Jul 19, 2019

asvetlov added a commit that referenced this issue Jul 20, 2019
[3.5] Close session on error in aiohttp.request (#3628) (#3640) (#3917)
(cherry picked from commit 20bfadc)

Co-authored-by: Robert Nikolich <rob-joy@yandex.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.