diff --git a/uvloop/loop.pyx b/uvloop/loop.pyx index 577d45a4..98d6b668 100644 --- a/uvloop/loop.pyx +++ b/uvloop/loop.pyx @@ -1869,6 +1869,7 @@ cdef class Loop: AddrInfo ai_local = None AddrInfo ai_remote TCPTransport tr + int sockfd system.addrinfo *rai = NULL system.addrinfo *lai = NULL @@ -2052,8 +2053,10 @@ cdef class Loop: waiter = self._new_future() tr = TCPTransport.new(self, protocol, None, waiter, context) try: + # Take ownership of the file descriptor + sockfd = sock.detach() # libuv will make socket non-blocking - tr._open(sock.fileno()) + tr._open(sockfd) tr._init_protocol() await waiter except (KeyboardInterrupt, SystemExit): @@ -2067,8 +2070,6 @@ cdef class Loop: tr._close() raise - tr._attach_fileobj(sock) - if ssl: app_transport = protocol._get_app_transport(context) try: