Skip to content

Commit 5f18f73

Browse files
committed
Close transport after sending close_notify in TLSv1.2
See MagicStack#471 for details.
1 parent afb3268 commit 5f18f73

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

uvloop/includes/consts.pxi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ DEF LOG_THRESHOLD_FOR_CONNLOST_WRITES = 5
2020
# The default timeout matches that of Nginx.
2121
DEF SSL_HANDSHAKE_TIMEOUT = 60.0
2222
# Number of seconds to wait for SSL shutdown to complete
23-
# The default timeout mimics lingering_time
24-
DEF SSL_SHUTDOWN_TIMEOUT = 30.0
23+
DEF SSL_SHUTDOWN_TIMEOUT = 10.0
2524
DEF SSL_READ_MAX_SIZE = 256 * 1024

uvloop/sslproto.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ cdef class SSLProtocol:
8484
object _handshake_timeout_handle
8585
object _shutdown_timeout_handle
8686

87+
str _ssl_version
88+
8789
cdef _set_app_protocol(self, app_protocol)
8890
cdef _wakeup_waiter(self, exc=*)
8991
cdef _get_extra_info(self, name, default=*)

uvloop/sslproto.pyx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ cdef class SSLProtocol:
536536
cipher=sslobj.cipher(),
537537
compression=sslobj.compression(),
538538
ssl_object=sslobj)
539+
self._ssl_version = sslobj.version()
539540
if self._app_state == STATE_INIT:
540541
self._app_state = STATE_CON_MADE
541542
self._app_protocol.connection_made(self._get_app_transport())
@@ -585,6 +586,9 @@ cdef class SSLProtocol:
585586
"""
586587
cdef:
587588
bint close_notify = False
589+
if self._app_state == STATE_EOF:
590+
# close_notify was already received
591+
return
588592
try:
589593
while True:
590594
if not self._sslobj_read(SSL_READ_MAX_SIZE):
@@ -626,6 +630,11 @@ cdef class SSLProtocol:
626630
self._sslobj.unwrap()
627631
except ssl_SSLAgainErrors as exc:
628632
self._process_outgoing()
633+
if self._ssl_version != "TLSv1.3":
634+
# don't wait for close_notify from the peer in TLSv1.2 or
635+
# lower to conform with widespread implementation practice
636+
if not self._get_write_buffer_size():
637+
self._on_shutdown_complete(None)
629638
else:
630639
self._process_outgoing()
631640
if not self._get_write_buffer_size():

0 commit comments

Comments
 (0)