@@ -952,23 +952,34 @@ def __init__(self, loop, sock, protocol, waiter=None,
952952 extra = None , server = None , context = None ):
953953 self ._read_ready_cb = None
954954 super ().__init__ (loop , sock , protocol , extra , server , context )
955- self ._eof = False
956- self ._empty_waiter = None
957- if _HAS_SENDMSG :
958- self ._write_ready = self ._write_sendmsg
959- else :
960- self ._write_ready = self ._write_send
961- # Disable the Nagle algorithm -- small writes will be
962- # sent without waiting for the TCP ACK. This generally
963- # decreases the latency (in some cases significantly.)
964- base_events ._set_nodelay (self ._sock )
965-
966- self ._call_soon (self ._protocol .connection_made , self )
967- # only start reading when connection_made() has been called
968- self ._call_soon (self ._add_reader , self ._sock_fd , self ._read_ready )
969- if waiter is not None :
970- # only wake up the waiter when connection_made() has been called
971- self ._call_soon (futures ._set_result_unless_cancelled , waiter , None )
955+ try :
956+ self ._eof = False
957+ self ._empty_waiter = None
958+ if _HAS_SENDMSG :
959+ self ._write_ready = self ._write_sendmsg
960+ else :
961+ self ._write_ready = self ._write_send
962+ # Disable the Nagle algorithm -- small writes will be
963+ # sent without waiting for the TCP ACK. This generally
964+ # decreases the latency (in some cases significantly.)
965+ base_events ._set_nodelay (self ._sock )
966+
967+ self ._call_soon (self ._protocol .connection_made , self )
968+ # only start reading when connection_made() has been called
969+ self ._call_soon (self ._add_reader , self ._sock_fd ,
970+ self ._read_ready )
971+ if waiter is not None :
972+ # only wake up the waiter when connection_made() has been
973+ # called
974+ self ._call_soon (futures ._set_result_unless_cancelled ,
975+ waiter , None )
976+ except BaseException :
977+ if self ._loop ._transports .get (self ._sock_fd ) is self :
978+ del self ._loop ._transports [self ._sock_fd ]
979+ if self ._server is not None :
980+ self ._server ._detach (self )
981+ self ._server = None
982+ raise
972983
973984 def set_protocol (self , protocol ):
974985 if isinstance (protocol , protocols .BufferedProtocol ):
0 commit comments