@@ -975,7 +975,7 @@ cdef class Loop:
975975
976976 if UVLOOP_DEBUG:
977977 if fut.cancelled():
978- # Shouldn't happen with _SyncSocketReaderFuture .
978+ # Shouldn't happen with _SyncSocketWriterFuture .
979979 raise RuntimeError (
980980 f' _sock_sendall is called on a cancelled Future' )
981981
@@ -1044,9 +1044,7 @@ cdef class Loop:
10441044 else :
10451045 return
10461046
1047- fut = self ._new_future()
1048- fut.add_done_callback(lambda fut : self ._remove_writer(sock))
1049-
1047+ fut = _SyncSocketWriterFuture(sock, self )
10501048 handle = new_MethodHandle3(
10511049 self ,
10521050 " Loop._sock_connect" ,
@@ -1059,8 +1057,16 @@ cdef class Loop:
10591057 return fut
10601058
10611059 cdef _sock_connect_cb(self , fut, sock, address):
1062- if fut.cancelled():
1063- return
1060+ if UVLOOP_DEBUG:
1061+ if fut.cancelled():
1062+ # Shouldn't happen with _SyncSocketWriterFuture.
1063+ raise RuntimeError (
1064+ f' _sock_connect_cb is called on a cancelled Future' )
1065+
1066+ if not self ._has_writer(sock):
1067+ raise RuntimeError (
1068+ f' socket {sock!r} does not have a writer '
1069+ f' in the _sock_connect_cb callback' )
10641070
10651071 try :
10661072 err = sock.getsockopt(uv.SOL_SOCKET, uv.SO_ERROR)
@@ -1074,8 +1080,10 @@ cdef class Loop:
10741080 raise
10751081 except BaseException as exc:
10761082 fut.set_exception(exc)
1083+ self ._remove_writer(sock)
10771084 else :
10781085 fut.set_result(None )
1086+ self ._remove_writer(sock)
10791087
10801088 cdef _sock_set_reuseport(self , int fd):
10811089 cdef:
0 commit comments