Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6459c8d

Browse files
committed
Fix for SF buf #458835
Try to be systematic about dealing with socket and ssl exceptions in FakeSocket.makefile(). The previous version of the code caught all ssl errors and treated them as EOF, even though most of the errors don't mean EOF. An SSL error can mean on of three things: 1. The SSL/TLS connection was closed. 2. The operation should be retried. 3. An error occurred. Also, if a socket error occurred and the error was EINTR, retry the call. Otherwise, it was a legitimate error and the caller should receive the exception.
1 parent e2adc6c commit 6459c8d

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

Lib/httplib.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@
6666
Req-sent-unread-response _CS_REQ_SENT <response_class>
6767
"""
6868

69-
import socket
69+
import errno
7070
import mimetools
71+
import socket
7172

7273
try:
7374
from cStringIO import StringIO
@@ -604,8 +605,18 @@ def makefile(self, mode, bufsize=None):
604605
while 1:
605606
try:
606607
buf = self.__ssl.read()
607-
except socket.sslerror, msg:
608-
break
608+
except socket.sslerror, err:
609+
if (err[0] == socket.SSL_ERROR_WANT_READ
610+
or err[0] == socket.SSL_ERROR_WANT_WRITE
611+
or 0):
612+
continue
613+
if err[0] == socket.SSL_ERROR_ZERO_RETURN:
614+
break
615+
raise
616+
except socket.error, err:
617+
if err[0] = errno.EINTR:
618+
continue
619+
raise
609620
if buf == '':
610621
break
611622
msgbuf.append(buf)

0 commit comments

Comments
 (0)