File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -276,15 +276,20 @@ cdef class UVSocketHandle(UVHandle):
276276 # This code will only run for transports created from
277277 # Python sockets, i.e. with `loop.create_server(sock=sock)` etc.
278278 if self ._fileobj is not None :
279- try :
280- socket_dec_io_ref(self ._fileobj)
281-
282- # `socket.close()` will raise an EBADF because libuv
283- # has already closed the underlying FDself.
284- self ._fileobj.close()
285- except OSError as ex:
286- if ex.errno != errno_EBADF:
287- raise
279+ if isinstance (self ._fileobj, socket_socket):
280+ # Detaching the socket object is an ideal solution:
281+ # * libuv will actually close the FD
282+ # * detach() call will reset FD for the Python socket
283+ # object, which means that it won't be closed 2 times.
284+ self ._fileobj.detach()
285+ else :
286+ try :
287+ # `socket.close()` will raise an EBADF because libuv
288+ # has already closed the underlying FDself.
289+ self ._fileobj.close()
290+ except OSError as ex:
291+ if ex.errno != errno_EBADF:
292+ raise
288293 except Exception as ex:
289294 self ._loop.call_exception_handler({
290295 ' exception' : ex,
You can’t perform that action at this time.
0 commit comments