File tree Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -276,15 +276,20 @@ cdef class UVSocketHandle(UVHandle):
276
276
# This code will only run for transports created from
277
277
# Python sockets, i.e. with `loop.create_server(sock=sock)` etc.
278
278
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
288
293
except Exception as ex:
289
294
self ._loop.call_exception_handler({
290
295
' exception' : ex,
You can’t perform that action at this time.
0 commit comments