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 1
1
import asyncio
2
+ import logging
2
3
import socket
3
- import unittest
4
+ import unittest . mock
4
5
import uvloop
5
6
import sys
6
7
@@ -499,6 +500,23 @@ async def start_server():
499
500
500
501
self .loop .run_until_complete (start_server ())
501
502
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
+
502
520
503
521
class Test_UV_TCP (_TestTCP , tb .UVTestCase ):
504
522
Original file line number Diff line number Diff line change @@ -608,7 +608,13 @@ cdef class UVStream(UVBaseTransport):
608
608
if exc is None :
609
609
self ._init_protocol()
610
610
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():
612
618
self ._fatal_error(exc, False , " connect failed" )
613
619
else :
614
620
self ._waiter.set_exception(exc)
You can’t perform that action at this time.
0 commit comments