Title: asyncio sslproto do not shutdown ssl layer cleanly
Type: behavior Stage:
Components: asyncio Versions: Python 3.7, Python 3.6, Python 3.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: grzgrzgrz3, thehesiod, yselivanov
Priority: normal Keywords:

Created on 2017-06-18 22:08 by grzgrzgrz3, last changed 2017-06-21 09:17 by grzgrzgrz3.

Pull Requests
URL Status Linked Edit
PR 2270 open grzgrzgrz3, 2017-06-18 22:12
Messages (2)
msg296295 - (view) Author: Grzegorz Grzywacz (grzgrzgrz3) * Date: 2017-06-18 22:08
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.
msg296531 - (view) Author: Grzegorz Grzywacz (grzgrzgrz3) * Date: 2017-06-21 09:17
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:

1. ideal:

asyncio   ---------->   nginx
Ideal situation asyncio sending shutdown and nginx replies back. This is how it works before attached PR.

2. we can't relay on nginx

asyncio   ---------->   nginx

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 #29406.

Attached PR "fix" this problem (note is not ideal fix, more like workaround):

3. with fix:

asyncio   ---------->   nginx
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 #29406 propose. This will allow to implement SSL downgrade to
plain text.

Second situation, nginx sent ssl eof.

1. before fix:
nginx     ---------->   asyncio
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.

2. after fix:
nginx     ---------->   asyncio

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.
Date User Action Args
2017-06-21 09:17:37grzgrzgrz3setmessages: + msg296531
2017-06-19 19:49:35thehesiodsetnosy: + thehesiod
2017-06-18 22:13:00grzgrzgrz3setpull_requests: + pull_request2320
2017-06-18 22:08:35grzgrzgrz3create