[3.11] GH-113214: Fix SSLProto exception handling in SSL-over-SSL scenarios (GH-113334) (#113340)

When wrapped, `_SSLProtocolTransport._force_close(exc)` is called just like in the unwrapped scenario `_SelectorTransport._force_close(exc)` or `_ProactorBasePipeTransport._force_close(exc)` would be called, except here the exception needs to be passed through the `SSLProtocol._abort()` method, which didn't accept an exception object.

This commit ensures that this path works, in the same way that the uvloop implementation of SSLProto passes on the exception (on which the current implementation of SSLProto is based).

(cherry picked from commit 1ff0238594)

Co-authored-by: Martijn Pieters <mj@zopatista.com>
This commit is contained in:
Miss Islington (bot) 2023-12-21 01:51:51 +01:00 committed by GitHub
parent d65dfc8238
commit 9cbe4738bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 8 deletions

View file

@ -243,13 +243,12 @@ class _SSLProtocolTransport(transports._FlowControlMixin,
The protocol's connection_lost() method will (eventually) be
called with None as its argument.
"""
self._closed = True
if self._ssl_protocol is not None:
self._ssl_protocol._abort()
self._force_close(None)
def _force_close(self, exc):
self._closed = True
self._ssl_protocol._abort(exc)
if self._ssl_protocol is not None:
self._ssl_protocol._abort(exc)
def _test__append_write_backlog(self, data):
# for test only
@ -614,7 +613,7 @@ class SSLProtocol(protocols.BufferedProtocol):
if self._app_transport is not None:
self._app_transport._closed = True
if self._state == SSLProtocolState.DO_HANDSHAKE:
self._abort()
self._abort(None)
else:
self._set_state(SSLProtocolState.FLUSHING)
self._shutdown_timeout_handle = self._loop.call_later(
@ -661,10 +660,10 @@ class SSLProtocol(protocols.BufferedProtocol):
else:
self._loop.call_soon(self._transport.close)
def _abort(self):
def _abort(self, exc):
self._set_state(SSLProtocolState.UNWRAPPED)
if self._transport is not None:
self._transport.abort()
self._transport._force_close(exc)
# Outgoing flow