-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asyncio possible Improvement: Using shutdown()
Before close()
in _close_self_pipe
#130850
Comments
shutdown()
Before close()
in _close_self_pipe
shutdown()
Before close()
in _close_self_pipe
I am not a member of python in any way, but here is my input: Your Proposed Change: Adding a shutdown(socket.SHUT_RDWR) call before close() for both _ssock and _csock. Benefits:
Downsides: Extra Function Call: Introduces an additional function call (shutdown()) which might be unnecessary in some scenarios where close() is sufficient. Error Handling: Requires handling potential exceptions from the shutdown() call. |
I could make a pr |
yeah I'll make a pr on this branch |
done writing unittests |
I'll post a pr when I fix all the issues |
Hello @sharktide, Thank you for reviewing and submitting a PR for issue this Issue! I really appreciate your time and effort. I came across a similar case in the Thanks again! |
I'll check it out! |
The self pipe is only ever written by the wakeup fd as such there is no need to shutdown it, it can be closed safely. |
Description
While reviewing the
_close_self_pipe
method inLib/asyncio/selector_events.py
, I noticed that the sockets_ssock
and_csock
are directly closed usingclose()
, without first callingshutdown()
.Code Reference
Question
Would there be any potential downsides or benefits to adding a shutdown(socket.SHUT_RDWR) call before closing these sockets?
Possible Benefits
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
The text was updated successfully, but these errors were encountered: