This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: SSL socket does not respect SO_RCVTIME0 timeouts
Type: behavior Stage: resolved
Components: SSL Versions: Python 3.5, Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: allanc, christian.heimes
Priority: normal Keywords:

Created on 2017-06-03 21:15 by allanc, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
httpdelay.py allanc, 2017-06-03 21:15
Messages (2)
msg295106 - (view) Author: Allan Crooks (allanc) Date: 2017-06-03 21:15
I initially filed this ticket against the ldap3 library, as this is where I first encountered the issue: https://github.com/cannatag/ldap3/issues/356

I've attached a file which reproduces the issue using the standard library - it makes both a HTTP and HTTPS request to a link that should return a HTTP response after 10 seconds, but we set the socket option SO_RCVTIMEO to 2 seconds. This should result in a read timeout while waiting for a response.

On my 64 bit Ubuntu 16.04 machine, the HTTP connection times out as expected, but the HTTPS connection doesn't time out at all (and so ends up reading the HTTP response).

It doesn't seem to be an issue specific to HTTPS - I ran into the original issue while using TLS for an LDAP connection using the ldap3 library. If you follow the comments in the ticket, a connection with SO_RCVTIMEO set to 3 seconds ended up taking 1076 seconds to timeout, while on an OSX machine, it took 148 seconds to timeout. On a Windows machine, it seems to work just fine (it timed out after the desired 3 seconds).

Is this option fully supported for SSL sockets?
msg295280 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2017-06-06 17:27
SO_RCVTIME0 works only with operating system level sockets. A SSLSocket is not an OS level. It's a high level abstraction layer that wraps either a file descriptor or a memory BIO. A read operation on a SSLSocket can perform write, a write operation can perform read. For the initial handshake, it will do both.

This means that SO_RCVTIME0 is not supported. Either you have to use the SSLSocket's timeout feature or do your own socket io and use a memory BIO. The internal timeout feature is build around select()/poll() syscall and low level OpenSSL calls.
History
Date User Action Args
2022-04-11 14:58:47adminsetgithub: 74747
2017-06-06 17:27:31christian.heimessetstatus: open -> closed
resolution: wont fix
messages: + msg295280

stage: resolved
2017-06-03 21:15:42allanccreate