From: Antoine Pitrou Date: Wed, 4 Mar 2015 19:54:57 +0000 (+0100) Subject: Issue #23576: Avoid stalling in SSL reads when EOF has been reached in the SSL layer... X-Git-Tag: v3.5.0a2~33 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0bfd0a40486d1eac92572e7272d25e3e405b7aef;p=python Issue #23576: Avoid stalling in SSL reads when EOF has been reached in the SSL layer but the underlying connection hasn't been closed. --- 0bfd0a40486d1eac92572e7272d25e3e405b7aef diff --cc Misc/NEWS index 0e0b2a5802,129843472f..7f1b7ad1db --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -13,18 -13,13 +13,21 @@@ Core and Builtin Library ------- + - Issue #23576: Avoid stalling in SSL reads when EOF has been reached in the + SSL layer but the underlying connection hasn't been closed. + - Issue #23504: Added an __all__ to the types module. +- Issue #23563: Optimized utility functions in urllib.parse. + +- Issue #7830: Flatten nested functools.partial. + - Issue #20204: Added the __module__ attribute to _tkinter classes. +- Issue #19980: Improved help() for non-recognized strings. help('') now + shows the help on str. help('help') now shows the help on help(). + Original patch by Mark Lawrence. + - Issue #23521: Corrected pure python implementation of timedelta division. * Eliminated OverflowError from timedelta * float for some floats; diff --cc Modules/_ssl.c index 0e6abda975,e7ba583949..4f23097990 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@@ -1834,33 -1712,11 +1834,13 @@@ static PyObject *PySSL_SSLread(PySSLSoc } } - /* just in case the blocking state of the socket has been changed */ - nonblocking = (sock->sock_timeout >= 0.0); - BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); - BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking); + if (sock != NULL) { + /* just in case the blocking state of the socket has been changed */ + nonblocking = (sock->sock_timeout >= 0.0); + BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); + BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking); + } - /* first check if there are bytes ready to be read */ - PySSL_BEGIN_ALLOW_THREADS - count = SSL_pending(self->ssl); - PySSL_END_ALLOW_THREADS - - if (!count) { - sockstate = check_socket_and_wait_for_timeout(sock, 0); - if (sockstate == SOCKET_HAS_TIMED_OUT) { - PyErr_SetString(PySocketModule.timeout_error, - "The read operation timed out"); - goto error; - } else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) { - PyErr_SetString(PySSLErrorObject, - "Underlying socket too large for select()."); - goto error; - } else if (sockstate == SOCKET_HAS_BEEN_CLOSED) { - count = 0; - goto done; - } - } do { PySSL_BEGIN_ALLOW_THREADS count = SSL_read(self->ssl, mem, len);