You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
asyncio sslproto do not shutdown ssl layer cleanly #74883
Asyncio on shutdown do not send shutdown confirmation to the other side. _SSLPipe after doing unwrap is calling shutdown callback where transport is closed and quit ssldata wont be sent.
No one yet responded, maybe this is unclear. I will clarify what is going on, why i made this change, what we gain from this and why this is not ideal solution.
I will focus on ssl layer shutdown as this issue regards.
We have connection asyncio <-> nginx
Lets see first situation asyncio initiates shutdown:
ideal:
shutdown
asyncio ----------> nginx
<----------
shutdown
Ideal situation asyncio sending shutdown and nginx replies back. This is how it works before attached PR.
we can't relay on nginx
shutdown
asyncio ----------> nginx
|||||||||||
shutdown
At this point everything looks great, but what will happen when nginx do not sent shutdown - we will wait forever.
We have this situation here bpo-29406.
Attached PR "fix" this problem (note is not ideal fix, more like workaround):
with fix:
shutdown
asyncio ----------> nginx
||?--------
shutdown
asyncio is sending shutdown ssl data to nginx but not waiting for nginx response, transport is closed anyway. I think ideal will
be to wait for certain amount of time for response like Nikolay in bpo-29406 propose. This will allow to implement SSL downgrade to
plain text.
Second situation, nginx sent ssl eof.
before fix:
shutdown
nginx ----------> asyncio
|||||||||||
shutdown
In this case we are receiving nginx shutdown and correctly process it but after that, shutdown callback will close the transport before
shutdown is sent back. Asyncio will try to send this data but fail due to closed transport. There is another issue should be not possible
to write to closed transport. We are getting false-positive result to write. I do not analyze this deeper,
maybe there is a reason to it.
after fix:
shutdown
nginx ----------> asyncio
<----------
shutdown
This is clean, shutdown callback in _SSLPipe is removed. We close transport in ssl protocol.
I think connections between _SSLPipe and ssl protocol has design problems, _SSLPipe should be, as name suggest, only a pipe.
Callback for handshake and shutdown feels wrong. Ssl protocol based on _SSLPipie mode and state can figure out when to call
connection_made or close transport.
Activity
grzgrzgrz3 commentedon Jun 18, 2017
Asyncio on shutdown do not send shutdown confirmation to the other side. _SSLPipe after doing unwrap is calling shutdown callback where transport is closed and quit ssldata wont be sent.
grzgrzgrz3 commentedon Jun 21, 2017
No one yet responded, maybe this is unclear. I will clarify what is going on, why i made this change, what we gain from this and why this is not ideal solution.
I will focus on ssl layer shutdown as this issue regards.
We have connection asyncio <-> nginx
Lets see first situation asyncio initiates shutdown:
ideal:
asyncio ----------> nginx
<----------
shutdown
Ideal situation asyncio sending shutdown and nginx replies back. This is how it works before attached PR.
we can't relay on nginx
asyncio ----------> nginx
|||||||||||
shutdown
At this point everything looks great, but what will happen when nginx do not sent shutdown - we will wait forever.
We have this situation here bpo-29406.
Attached PR "fix" this problem (note is not ideal fix, more like workaround):
with fix:
asyncio ----------> nginx
||?--------
shutdown
asyncio is sending shutdown ssl data to nginx but not waiting for nginx response, transport is closed anyway. I think ideal will
be to wait for certain amount of time for response like Nikolay in bpo-29406 propose. This will allow to implement SSL downgrade to
plain text.
Second situation, nginx sent ssl eof.
before fix:
shutdown
nginx ----------> asyncio
|||||||||||
shutdown
In this case we are receiving nginx shutdown and correctly process it but after that, shutdown callback will close the transport before
shutdown is sent back. Asyncio will try to send this data but fail due to closed transport. There is another issue should be not possible
to write to closed transport. We are getting false-positive result to write. I do not analyze this deeper,
maybe there is a reason to it.
after fix:
shutdown
nginx ----------> asyncio
<----------
shutdown
This is clean, shutdown callback in _SSLPipe is removed. We close transport in ssl protocol.
I think connections between _SSLPipe and ssl protocol has design problems, _SSLPipe should be, as name suggest, only a pipe.
Callback for handshake and shutdown feels wrong. Ssl protocol based on _SSLPipie mode and state can figure out when to call
connection_made or close transport.
thehesiod commentedon Jan 11, 2018
@grzgrzgrz3, does this resolve the issue in https://bugs.python.org/issue29406 ? I'm guessing you based this PR on that issue. If so I'd like it merged ASAP as otherwise our prod services will be incompatible with all future python releases given the original "fix" was reverted. Thanks!
grzgrzgrz3 commentedon Jan 11, 2018
No, this PR originally fix similar but different issue.
However it also fix bpo-29406 as a side effect.
1st1 commentedon May 25, 2018
Is this issue resolved now, or do we need to work on this?
legnaleurc commentedon Oct 15, 2018
The SSL connection still cannot close cleanly in 3.7.0.
It will keep throwing read error during shutdown, so shutdown callback will never be called.
I've been test this PR for a while, and at least it fixes my problem.
Hope this PR can be included in 3.7.1, or at least 3.7.2.
Zheaoli commentedon Dec 22, 2018
Ping!
Agree with Wei-Cheng.
The leak still bothers me for times, and still bother for third-party like https://aiohttp.readthedocs.io/en/stable/client_reference.html#tcpconnector
Yury, I think it's worth working on it. Using uvloop should not be a good idea for some people.
kumaraditya303 commentedon Feb 28, 2022
Since https://bugs.python.org/issue44011 is fixed now, this can be closed.
@asvetlov
asvetlov commentedon Feb 28, 2022
Agree