Skip to content

Commit 7fcbfed

Browse files
fantix1st1
authored andcommitted
fix None _shutdown_timeout_handle issue
* Fixes #255 * Also make handles more robust
1 parent b2aa8db commit 7fcbfed

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

tests/test_tcp.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,6 +2891,50 @@ async def client(addr, ctx):
28912891
# SSLProtocol should be DECREF to 0
28922892
self.assertIsNone(ctx())
28932893

2894+
def test_shutdown_timeout_handler_not_set(self):
2895+
loop = self.loop
2896+
2897+
def server(sock):
2898+
sslctx = self._create_server_ssl_context(self.ONLYCERT,
2899+
self.ONLYKEY)
2900+
sock = sslctx.wrap_socket(sock, server_side=True)
2901+
sock.send(b'hello')
2902+
assert sock.recv(1024) == b'world'
2903+
time.sleep(0.1)
2904+
sock.send(b'extra bytes' * 1)
2905+
# sending EOF here
2906+
sock.shutdown(socket.SHUT_WR)
2907+
# make sure we have enough time to reproduce the issue
2908+
time.sleep(0.1)
2909+
sock.close()
2910+
2911+
class Protocol(asyncio.Protocol):
2912+
def __init__(self):
2913+
self.fut = asyncio.Future(loop=loop)
2914+
self.transport = None
2915+
2916+
def connection_made(self, transport):
2917+
self.transport = transport
2918+
2919+
def data_received(self, data):
2920+
self.transport.write(b'world')
2921+
# pause reading would make incoming data stay in the sslobj
2922+
self.transport.pause_reading()
2923+
# resume for AIO to pass
2924+
loop.call_later(0.2, self.transport.resume_reading)
2925+
2926+
def connection_lost(self, exc):
2927+
self.fut.set_result(None)
2928+
2929+
async def client(addr):
2930+
ctx = self._create_client_ssl_context()
2931+
tr, pr = await loop.create_connection(Protocol, *addr, ssl=ctx)
2932+
await pr.fut
2933+
tr.close()
2934+
2935+
with self.tcp_server(server) as srv:
2936+
loop.run_until_complete(client(srv.addr))
2937+
28942938

28952939
class Test_UV_TCPSSL(_TestSSL, tb.UVTestCase):
28962940
pass

uvloop/sslproto.pyx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,10 @@ cdef class SSLProtocol:
349349

350350
if self._shutdown_timeout_handle:
351351
self._shutdown_timeout_handle.cancel()
352+
self._shutdown_timeout_handle = None
352353
if self._handshake_timeout_handle:
353354
self._handshake_timeout_handle.cancel()
355+
self._handshake_timeout_handle = None
354356

355357
def get_buffer(self, n):
356358
cdef size_t want = n
@@ -495,7 +497,9 @@ cdef class SSLProtocol:
495497
self._on_handshake_complete(None)
496498

497499
cdef _on_handshake_complete(self, handshake_exc):
498-
self._handshake_timeout_handle.cancel()
500+
if self._handshake_timeout_handle is not None:
501+
self._handshake_timeout_handle.cancel()
502+
self._shutdown_timeout_handle = None
499503

500504
sslobj = self._sslobj
501505
try:
@@ -588,7 +592,9 @@ cdef class SSLProtocol:
588592
self._on_shutdown_complete(None)
589593

590594
cdef _on_shutdown_complete(self, shutdown_exc):
591-
self._shutdown_timeout_handle.cancel()
595+
if self._shutdown_timeout_handle is not None:
596+
self._shutdown_timeout_handle.cancel()
597+
self._shutdown_timeout_handle = None
592598

593599
if shutdown_exc:
594600
self._fatal_error(shutdown_exc)

0 commit comments

Comments
 (0)