-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-85972: Use native timeout for inet socket operations #110988
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
base: main
Are you sure you want to change the base?
Conversation
This reverts commit 6c0159f.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few code suggestions and comment typos, but otherwise looks good to me. I'm not a sockets programmer though, so I'd appreciate someone confirming that this is good across platforms and that the tests have it covered.
| @@ -3421,6 +3540,13 @@ internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen, | |||
|
|
|||
| /* save error, PyErr_CheckSignals() can replace it */ | |||
| err = GET_SOCK_ERROR; | |||
|
|
|||
| if (s->sock_timeout > 0) { | |||
| if (internal_setblocking(s, 1) < 0) { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this call not affect errno? And hence the following CHECK_ERRNO checks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I checked and found that it does. Updated to use the pre-stored errno to avoid this.
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
|
Thanks for the review! I added some note on the first comment of this PR. |
I have a dig into using
SO_SENDTIMEOandSO_RECVTIMEOto implement the timeout operation, and found that most platforms support using them to set thewrite/send/read/recv... timeouts for INET sockets.For Unix domain sockets, only Linux supports using these options to set the timeout.
For
connect/accept,SO_SENDTIMEOandSO_RECVTIMEOalso affect these two operations' timeout on Linux.So, in this PR, Unix domain sockets will keep the old behavior (use setblocking(0) and select to emulate timeout).
For INET sockets,
socket.settimeoutwill useSO_SENDTIMEOandSO_RECVTIMEOoptions to set the timeout to the socket directly and use this to enforce a timeout.For INET sockets,
connectwill use the old behavior (use setblocking(0) and select to emulate timeout) to enforce a timeout. To achieve this, we should set it to non-blocking mode and call the oldconnect, then set it to blocking mode again.