Title: asyncio sock_recv blocks on ssl sockets.
Type: behavior Stage: patch review
Components: asyncio, SSL Versions: Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: AkshayTakkar, asvetlov, christian.heimes, yselivanov
Priority: normal Keywords: patch

Created on 2019-06-25 19:36 by AkshayTakkar, last changed 2019-06-28 18:01 by AkshayTakkar.

File name Uploaded Description Edit
server_client AkshayTakkar, 2019-06-25 19:36 Server/Client Code to replicate the issue. Note: You'll have to create the certificate.pem and key.pem files
Pull Requests
URL Status Linked Edit
PR 14457 closed AkshayTakkar, 2019-06-28 18:01
Messages (5)
msg346550 - (view) Author: Akshay Takkar (AkshayTakkar) * Date: 2019-06-25 19:36
I'm working on a server that uses sock_recv from asyncio.
await sock_recv(socket, n) never returns if socket is wrapped in ssl using the wrap_socket function from the ssl module.
I think the problem stated in this stackoverflow question could be the reason:
msg346552 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2019-06-25 19:42
You can't use sock_recv() with a wrapped SSL socket. A SSLSocket behaves differently because there is user-level buffering. The connection operates on TLS frames and only hands off data after it has been decrypted and verified. asyncio uses wrap_bio().
msg346597 - (view) Author: Akshay Takkar (AkshayTakkar) * Date: 2019-06-26 10:20
Can you please elaborate on how to get around this issue?
msg346598 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-06-26 10:35
Use asyncio transports or streams.
sock_recv() is a low-level API with a very limited audience.

wrapped ssl socket provides a synchronous interface only.

Perhaps we should raise an exception if SSLSocket is passed into asyncio functions.
msg346599 - (view) Author: Akshay Takkar (AkshayTakkar) * Date: 2019-06-26 10:48
Ah, I see. Yes, raising an exception would probably be very useful. Thanks for the info.
Date User Action Args
2019-06-28 18:01:56AkshayTakkarsetkeywords: + patch
stage: patch review
pull_requests: + pull_request14274
2019-06-26 10:48:50AkshayTakkarsetmessages: + msg346599
2019-06-26 10:35:47asvetlovsetmessages: + msg346598
2019-06-26 10:20:58AkshayTakkarsetmessages: + msg346597
2019-06-25 19:42:40christian.heimessetmessages: + msg346552
2019-06-25 19:36:21AkshayTakkarcreate