@@ -117,7 +117,12 @@ cdef class UVBaseTransport(UVSocketHandle):
117
117
cdef _wakeup_waiter(self ):
118
118
if self ._waiter is not None :
119
119
if not self ._waiter.cancelled():
120
- self ._waiter.set_result(True )
120
+ if not self ._is_alive():
121
+ self ._waiter.set_exception(
122
+ RuntimeError (
123
+ ' closed Transport handle and unset waiter' ))
124
+ else :
125
+ self ._waiter.set_result(True )
121
126
self ._waiter = None
122
127
123
128
cdef _call_connection_made(self ):
@@ -126,7 +131,10 @@ cdef class UVBaseTransport(UVSocketHandle):
126
131
raise RuntimeError (
127
132
' protocol is not set, cannot call connection_made()' )
128
133
129
- if self ._closing:
134
+ # We use `_is_alive()` and not `_closing`, because we call
135
+ # `transport._close()` in `loop.create_connection()` if an
136
+ # exception happens during `await waiter`.
137
+ if not self ._is_alive():
130
138
# A connection waiter can be cancelled between
131
139
# 'await loop.create_connection()' and
132
140
# `_schedule_call_connection_made` and
@@ -147,7 +155,7 @@ cdef class UVBaseTransport(UVSocketHandle):
147
155
self ._wakeup_waiter()
148
156
raise
149
157
150
- if self ._closing :
158
+ if not self ._is_alive() :
151
159
# This might happen when "transport.abort()" is called
152
160
# from "Protocol.connection_made".
153
161
self ._wakeup_waiter()
0 commit comments