Commit aaccf2d3 authored by Jason Madden's avatar Jason Madden

Fix #800

sslgte279 and ssl3: Move the check for _sslobj to inside the loop
instead of above it. That way if the socket is closed while
reading/writing (actually, while waiting for the read or write event)
then the ValueError will be raised on the next loop iteration (because
closing cancels the read/write events) instead of a TypeError.

This may or may not obviate the chances for an OSError: closed to be
raised.
parent e4e3d173
......@@ -99,6 +99,10 @@ Other Changes
present in Python 2), :func:`gevent.ssl.get_server_certificate`
would raise a :exc:`ValueError` if the system wasn't monkey-patched.
Reported in :issue:`801` by Gleb Dubovik.
- On Python 2.7.9 and Python 3, closing an SSL socket in one greenlet
while it's being read from or written to in a different greenlet is
less likely to raise a :exc:`TypeError` instead of a
:exc:`ValueError`. Reported in :issue:`800` by Kevin Chen.
1.1.1 (Apr 4, 2016)
===================
......
......@@ -221,10 +221,11 @@ class SSLSocket(socket):
Return zero-length string on EOF."""
# pylint:disable=too-many-branches
self._checkClosed()
while True:
if not self._sslobj:
raise ValueError("Read on closed or unwrapped SSL socket.")
while True:
try:
if buffer is not None:
return self._sslobj.read(len, buffer)
......@@ -252,10 +253,11 @@ class SSLSocket(socket):
"""Write DATA to the underlying SSL channel. Returns
number of bytes of DATA actually transmitted."""
self._checkClosed()
while True:
if not self._sslobj:
raise ValueError("Write on closed or unwrapped SSL socket.")
while True:
try:
return self._sslobj.write(data)
except SSLError as ex:
......
......@@ -300,9 +300,11 @@ class SSLSocket(socket):
"""Read up to LEN bytes and return them.
Return zero-length string on EOF."""
self._checkClosed()
while 1:
if not self._sslobj:
raise ValueError("Read on closed or unwrapped SSL socket.")
while True:
try:
if buffer is not None:
return self._sslobj.read(len, buffer)
......@@ -330,9 +332,11 @@ class SSLSocket(socket):
"""Write DATA to the underlying SSL channel. Returns
number of bytes of DATA actually transmitted."""
self._checkClosed()
while 1:
if not self._sslobj:
raise ValueError("Write on closed or unwrapped SSL socket.")
while True:
try:
return self._sslobj.write(data)
except SSLError as ex:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment