diff options
author | Nikolay Kim <fafhrd91@gmail.com> | 2017-06-10 04:04:39 (GMT) |
---|---|---|
committer | Yury Selivanov <yury@magic.io> | 2017-06-10 04:04:39 (GMT) |
commit | a608d2d5a7f1aabe9bcbfc220135c5e126189390 (patch) | |
tree | 8e360568addd6c6338effe49f2c9dea4464f5993 /Lib/asyncio | |
parent | 34792d25ab7329241ea24595286d65d54c266274 (diff) | |
download | cpython-a608d2d5a7f1aabe9bcbfc220135c5e126189390.zip cpython-a608d2d5a7f1aabe9bcbfc220135c5e126189390.tar.gz cpython-a608d2d5a7f1aabe9bcbfc220135c5e126189390.tar.bz2 |
bpo-29406: asyncio SSL contexts leak sockets after calling close with certain servers (#409)
* asyncio SSL contexts leak sockets after calling close with certain servers
* cleanup _shutdown_timeout_handle on _fatal_error
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/sslproto.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py index 68499e5..a36725e 100644 --- a/Lib/asyncio/sslproto.py +++ b/Lib/asyncio/sslproto.py @@ -6,6 +6,8 @@ except ImportError: # pragma: no cover ssl = None from . import base_events +from . import compat +from . import futures from . import protocols from . import transports from .log import logger @@ -407,7 +409,7 @@ class SSLProtocol(protocols.Protocol): def __init__(self, loop, app_protocol, sslcontext, waiter, server_side=False, server_hostname=None, - call_connection_made=True): + call_connection_made=True, shutdown_timeout=5.0): if ssl is None: raise RuntimeError('stdlib ssl module not available') @@ -438,6 +440,8 @@ class SSLProtocol(protocols.Protocol): self._session_established = False self._in_handshake = False self._in_shutdown = False + self._shutdown_timeout = shutdown_timeout + self._shutdown_timeout_handle = None # transport, ex: SelectorSocketTransport self._transport = None self._call_connection_made = call_connection_made @@ -552,6 +556,15 @@ class SSLProtocol(protocols.Protocol): self._in_shutdown = True self._write_appdata(b'') + if self._shutdown_timeout is not None: + self._shutdown_timeout_handle = self._loop.call_later( + self._shutdown_timeout, self._on_shutdown_timeout) + + def _on_shutdown_timeout(self): + if self._transport is not None: + self._fatal_error( + futures.TimeoutError(), 'Can not complete shitdown operation') + def _write_appdata(self, data): self._write_backlog.append((data, 0)) self._write_buffer_size += len(data) @@ -679,12 +692,22 @@ class SSLProtocol(protocols.Protocol): }) if self._transport: self._transport._force_close(exc) + self._transport = None + + if self._shutdown_timeout_handle is not None: + self._shutdown_timeout_handle.cancel() + self._shutdown_timeout_handle = None def _finalize(self): self._sslpipe = None if self._transport is not None: self._transport.close() + self._transport = None + + if self._shutdown_timeout_handle is not None: + self._shutdown_timeout_handle.cancel() + self._shutdown_timeout_handle = None def _abort(self): try: |