-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Closed as not planned
Closed as not planned
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancementA feature request or enhancement
Description
Description
While reviewing the _close_self_pipe method in Lib/asyncio/selector_events.py, I noticed that the sockets _ssock and _csock are directly closed using close(), without first calling shutdown().
Code Reference
def _close_self_pipe(self):
self._remove_reader(self._ssock.fileno())
self._ssock.close()
self._ssock = None
self._csock.close()
self._csock = None
self._internal_fds -= 1Question
Would there be any potential downsides or benefits to adding a shutdown(socket.SHUT_RDWR) call before closing these sockets?
Possible Benefits
- Ensures that all pending data is properly discarded before closing, particularly in scenarios where data might still be buffered.
- Prevents potential issues with lingering resources in some edge cases.
Aligns with best practices for socket cleanup.
Reference
The Python socket documentation states:
"close() releases the resource associated with a connection but does not necessarily close the connection immediately. If you want to close the connection in a timely fashion, call shutdown() before close()." link
Looking forward to your thoughts!
Thanks!
Linked PRs
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancementA feature request or enhancement
Projects
Status
Done