File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 11import asyncio
2+ import logging
23import socket
3- import unittest
4+ import unittest . mock
45import uvloop
56import sys
67
@@ -499,6 +500,23 @@ async def start_server():
499500
500501 self .loop .run_until_complete (start_server ())
501502
503+ def test_connect_silent_cancellation (self ):
504+ logger = logging .getLogger ('asyncio' )
505+
506+ srv_sock = socket .socket ()
507+ with srv_sock , unittest .mock .patch .object (logger , 'error' ) as log :
508+ srv_sock .bind (('127.0.0.1' , 0 ))
509+
510+ with self .assertRaises (asyncio .TimeoutError ):
511+ self .loop .run_until_complete (
512+ asyncio .wait_for (self .loop .create_connection (
513+ asyncio .Protocol , * srv_sock .getsockname ()),
514+ loop = self .loop , timeout = 0.1 ))
515+
516+ self .loop .run_until_complete (asyncio .sleep (0 , loop = self .loop ))
517+
518+ log .assert_not_called ()
519+
502520
503521class Test_UV_TCP (_TestTCP , tb .UVTestCase ):
504522
Original file line number Diff line number Diff line change @@ -608,7 +608,13 @@ cdef class UVStream(UVBaseTransport):
608608 if exc is None :
609609 self ._init_protocol()
610610 else :
611- if self ._waiter is None or self ._waiter.done():
611+ if self ._waiter is None :
612+ self ._fatal_error(exc, False , " connect failed" )
613+ elif self ._waiter.cancelled():
614+ # Connect call was cancelled; just close the transport
615+ # silently.
616+ self ._close()
617+ elif self ._waiter.done():
612618 self ._fatal_error(exc, False , " connect failed" )
613619 else :
614620 self ._waiter.set_exception(exc)
You can’t perform that action at this time.
0 commit comments