Skip to content

Commit edd3a0b

Browse files
committed
adjust error messages; restore old _fatal_error implementation
1 parent 9e412f0 commit edd3a0b

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

Lib/asyncio/sslproto.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from . import base_events
99
from . import constants
10-
from . import futures
1110
from . import protocols
1211
from . import transports
1312
from .log import logger
@@ -609,7 +608,7 @@ def _start_handshake(self):
609608
def _check_handshake_timeout(self):
610609
if self._in_handshake is True:
611610
msg = (
612-
f"SSL handshake for {self} is taking longer than "
611+
f"SSL handshake is taking longer than "
613612
f"{self._ssl_handshake_timeout} seconds: "
614613
f"aborting the connection"
615614
)
@@ -627,12 +626,9 @@ def _on_handshake_complete(self, handshake_exc):
627626
peercert = sslobj.getpeercert()
628627
except Exception as exc:
629628
if isinstance(exc, ssl.CertificateError):
630-
msg = (
631-
f'{self}: SSL handshake failed on verifying '
632-
f'the certificate'
633-
)
629+
msg = 'SSL handshake failed on verifying the certificate'
634630
else:
635-
msg = f'{self}: SSL handshake failed'
631+
msg = 'SSL handshake failed'
636632
self._fatal_error(exc, msg)
637633
return
638634

@@ -702,13 +698,19 @@ def _process_write_backlog(self):
702698
raise
703699

704700
def _fatal_error(self, exc, message='Fatal error on transport'):
701+
if isinstance(exc, base_events._FATAL_ERROR_IGNORE):
702+
if self._loop.get_debug():
703+
logger.debug("%r: %s", self, message, exc_info=True)
704+
else:
705+
self._loop.call_exception_handler({
706+
'message': message,
707+
'exception': exc,
708+
'transport': self._transport,
709+
'protocol': self,
710+
})
705711
if self._transport:
706712
self._transport._force_close(exc)
707713

708-
if (self._loop.get_debug() and
709-
isinstance(exc, base_events._FATAL_ERROR_IGNORE)):
710-
logger.debug("%r: %s", self, message, exc_info=True)
711-
712714
def _finalize(self):
713715
self._sslpipe = None
714716

Lib/test/test_asyncio/test_sslproto.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,7 @@ async def client(addr):
587587
self.assertEqual(messages, [])
588588

589589
def test_create_connection_ssl_failed_certificate(self):
590-
messages = []
591-
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
590+
self.loop.set_exception_handler(lambda loop, ctx: None)
592591

593592
sslctx = test_utils.simple_server_sslcontext()
594593
client_sslctx = test_utils.simple_client_sslcontext(
@@ -619,11 +618,8 @@ async def client(addr):
619618
with self.assertRaises(ssl.SSLCertVerificationError):
620619
self.loop.run_until_complete(client(srv.addr))
621620

622-
self.assertEqual(messages, [])
623-
624621
def test_start_tls_client_corrupted_ssl(self):
625-
messages = []
626-
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
622+
self.loop.set_exception_handler(lambda loop, ctx: None)
627623

628624
sslctx = test_utils.simple_server_sslcontext()
629625
client_sslctx = test_utils.simple_client_sslcontext()
@@ -662,7 +658,6 @@ async def client(addr):
662658
res = self.loop.run_until_complete(client(srv.addr))
663659

664660
self.assertEqual(res, 'OK')
665-
self.assertEqual(messages, [])
666661

667662

668663
@unittest.skipIf(ssl is None, 'No ssl module')

0 commit comments

Comments
 (0)