[Python-checkins] cpython (2.7): Issue #23576: Avoid stalling in SSL reads when EOF has been reached in the SSL

antoine.pitrou python-checkins at python.org
Wed Mar 4 21:08:51 CET 2015


https://hg.python.org/cpython/rev/371cf371a6a1
changeset:   94849:371cf371a6a1
branch:      2.7
parent:      94843:cb5fe8cc60eb
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Wed Mar 04 20:51:55 2015 +0100
summary:
  Issue #23576: Avoid stalling in SSL reads when EOF has been reached in the SSL layer but the underlying connection hasn't been closed.

files:
  Misc/NEWS      |   3 +++
  Modules/_ssl.c |  20 --------------------
  2 files changed, 3 insertions(+), 20 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -18,6 +18,9 @@
 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 #23458: On POSIX, the file descriptor kept open by os.urandom() is now
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1720,26 +1720,6 @@
     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(PySSLErrorObject,
-                            "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);

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list