Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tests/test_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2891,6 +2891,50 @@ async def client(addr, ctx):
# SSLProtocol should be DECREF to 0
self.assertIsNone(ctx())

def test_shutdown_timeout_handler_not_set(self):
loop = self.loop

def server(sock):
sslctx = self._create_server_ssl_context(self.ONLYCERT,
self.ONLYKEY)
sock = sslctx.wrap_socket(sock, server_side=True)
sock.send(b'hello')
assert sock.recv(1024) == b'world'
time.sleep(0.1)
sock.send(b'extra bytes' * 1)
# sending EOF here
sock.shutdown(socket.SHUT_WR)
# make sure we have enough time to reproduce the issue
time.sleep(0.1)
sock.close()

class Protocol(asyncio.Protocol):
def __init__(self):
self.fut = asyncio.Future(loop=loop)
self.transport = None

def connection_made(self, transport):
self.transport = transport

def data_received(self, data):
self.transport.write(b'world')
# pause reading would make incoming data stay in the sslobj
self.transport.pause_reading()
# resume for AIO to pass
loop.call_later(0.2, self.transport.resume_reading)

def connection_lost(self, exc):
self.fut.set_result(None)

async def client(addr):
ctx = self._create_client_ssl_context()
tr, pr = await loop.create_connection(Protocol, *addr, ssl=ctx)
await pr.fut
tr.close()

with self.tcp_server(server) as srv:
loop.run_until_complete(client(srv.addr))


class Test_UV_TCPSSL(_TestSSL, tb.UVTestCase):
pass
Expand Down
10 changes: 8 additions & 2 deletions uvloop/sslproto.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,10 @@ cdef class SSLProtocol:

if self._shutdown_timeout_handle:
self._shutdown_timeout_handle.cancel()
self._shutdown_timeout_handle = None
if self._handshake_timeout_handle:
self._handshake_timeout_handle.cancel()
self._handshake_timeout_handle = None

def get_buffer(self, n):
cdef size_t want = n
Expand Down Expand Up @@ -495,7 +497,9 @@ cdef class SSLProtocol:
self._on_handshake_complete(None)

cdef _on_handshake_complete(self, handshake_exc):
self._handshake_timeout_handle.cancel()
if self._handshake_timeout_handle is not None:
self._handshake_timeout_handle.cancel()
self._shutdown_timeout_handle = None

sslobj = self._sslobj
try:
Expand Down Expand Up @@ -588,7 +592,9 @@ cdef class SSLProtocol:
self._on_shutdown_complete(None)

cdef _on_shutdown_complete(self, shutdown_exc):
self._shutdown_timeout_handle.cancel()
if self._shutdown_timeout_handle is not None:
self._shutdown_timeout_handle.cancel()
Comment thread
fantix marked this conversation as resolved.
self._shutdown_timeout_handle = None

if shutdown_exc:
self._fatal_error(shutdown_exc)
Expand Down