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

Response context release #1571

Merged
merged 5 commits into from
Feb 1, 2017
Merged

Response context release #1571

merged 5 commits into from
Feb 1, 2017

Conversation

thehesiod
Copy link
Contributor

@thehesiod thehesiod commented Feb 1, 2017

don't close connections on exceptions as the library can't make that decision at this point. See discussion in #1568

@fafhrd91
Copy link
Member

fafhrd91 commented Feb 1, 2017

I don't think this is good solution. What would happen if http message actually malformed? In that case we cannot release connection

@thehesiod
Copy link
Contributor Author

thehesiod commented Feb 1, 2017

if it's malformed it should be handled where it's detected that it's malformed. The problem with this is that the exception can be anything, in my case I was just raising Exception from w/in the context causing it to close the connection for no reason.

@fafhrd91
Copy link
Member

fafhrd91 commented Feb 1, 2017

but when we do release(), connection get returned to pool, and in that case assumption is connection is clean and ready for re-use.

@thehesiod
Copy link
Contributor Author

can't release() check the transport status? or another way would be to add a custom exception and only close on that exception type. Can you show in the code where we note the transport is corrupt?

@fafhrd91
Copy link
Member

fafhrd91 commented Feb 1, 2017

transport is just opaque bytes stream. connection can be broken on http level

@thehesiod
Copy link
Contributor Author

either way the existing code is wrong, how do you know if an exception is not thrown that the transport can be released?

@fafhrd91
Copy link
Member

fafhrd91 commented Feb 1, 2017

if request parser completes http message parsing then connection is ready for re-use

@thehesiod
Copy link
Contributor Author

ok how does this sound, if http header parsing does not finish and exception is thrown close connection, otherwise release?

@fafhrd91
Copy link
Member

fafhrd91 commented Feb 1, 2017

btw what exception do you get? you also can print exc_type

@thehesiod
Copy link
Contributor Author

here's the issue:

async with http_session.get("http://foobar.com") as response:
   if resp.status != 200:
       raise Exception

this should not cause the connection to be closed as it can be re-used.

@fafhrd91
Copy link
Member

fafhrd91 commented Feb 1, 2017

ok, that makes sense

@fafhrd91
Copy link
Member

fafhrd91 commented Feb 1, 2017

here is what you need to do:

if resp.content.at_eof() and resp.content.exception() is None:
     resp.release()
else:
     resp.close()

@fafhrd91
Copy link
Member

fafhrd91 commented Feb 1, 2017

actually, wait a bit

@fafhrd91
Copy link
Member

fafhrd91 commented Feb 1, 2017

could you squash your commits?

@fafhrd91
Copy link
Member

fafhrd91 commented Feb 1, 2017

i modified release method, it should be save to call it even if connection is broken

@fafhrd91 fafhrd91 merged commit 7107386 into aio-libs:master Feb 1, 2017
@thehesiod
Copy link
Contributor Author

thank you so much for the quick work! I'm sure this has been lurking unnoticed in several people's workflows without them noticing since it "worked" before but would result in things moving slower than they needed to otherwise :)

@fafhrd91
Copy link
Member

fafhrd91 commented Feb 1, 2017

this may fix one of the issues, but to fix buggy ssl servers with need close timeout.

@thehesiod
Copy link
Contributor Author

what I'm doing locally is a custom release that forces transfer.abort() instead of .close() if it detects we have an ssl session to the buggy server until that patch is released. I was thinking perhaps aiohttp should enforce the connection limit by waiting until the connection is closed before creating new connections in the "pool". that would prevent socket "leaks" like these in the future but could make things slower if you're constantly closing connections. With the timeout fix you added I think we'll still go slightly over the connector limit while it waits for the close(s) to timeout.

@thehesiod thehesiod deleted the response-context-release branch February 1, 2017 21:20
@lock
Copy link

lock bot commented Oct 29, 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 Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants