You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sockmodule.c: sock_connect vs negative errno values... #84808
(Forgive any obvious mistakes in this report, I'm almost illiterate with Python, doubly so with Python internals.)
In trying to get buildbot-worker running on Haiku ( https://haiku-os.org/ ), it runs into a situation where it tries to connect a non-blocking TCP socket, which correctly reports EINPROGRESS, and cpython/Modules/sockmodule.c's internal_connect() returns this error code to sock_connect() and sock_connect_ex().
Both of the sock_connect* functions will return NULL if the error code is negative, but on Haiku, all the errno values are negative (EINPROGRESS, for example, is -2147454940).
I _think_ what sock_connect is intending to do here...
res=internal_connect(s, SAS2SA(&addrbuf), addrlen, 1);
if (res<0)
returnNULL;
...is say "if we had a devastating and unexpected system error, give up immediately." Buildbot-worker seems to confirm this by throwing this exception in response:
builtins.SystemError: <method 'connect_ex' of '_socket.socket' objects> returned NULL without setting an error
internal_connect returns -1 in those devastating-and-unexpected cases--namely when an exception is to be raised--and does not ever use that to otherwise signify a legit socket error. Linux and other systems don't otherwise fall into this "res < 0" condition because errno values are positive on those systems.
So I believe the correct fix here, in sock_connect() and sock_connect_ex(), is to check "if (res == -1)" instead of "res < 0" and let all other negative error codes carry on.
If this seems like the correct approach, I can assemble a pull request, but I don't know the full ramifications of this small change, so I thought I'd report it here first.
Since Haiku is not a supported platform, I'm relabelling this from bug to feature request. I don't know how likely it is that it will be implemented though, there would need to be a core developer who cares enough about Haiku to do something non-standard for it (an assess what the implications of that may be).
IMO, Python should not assume that errno codes are positive. The point of PEP-11 is to not maintain speedups/workarounds for niche platforms, not to overfit CPython to rely on quirks of the tiered platforms.
To me, this is a legitimate bug, though one that core devs won't fix alone, and might not prioritize.
Please send the PR. Considering the ramifications of the change is the reviewer's job.
Activity
rcgordon commentedon May 14, 2020
(Forgive any obvious mistakes in this report, I'm almost illiterate with Python, doubly so with Python internals.)
In trying to get buildbot-worker running on Haiku ( https://haiku-os.org/ ), it runs into a situation where it tries to connect a non-blocking TCP socket, which correctly reports EINPROGRESS, and cpython/Modules/sockmodule.c's internal_connect() returns this error code to sock_connect() and sock_connect_ex().
Both of the sock_connect* functions will return NULL if the error code is negative, but on Haiku, all the errno values are negative (EINPROGRESS, for example, is -2147454940).
I _think_ what sock_connect is intending to do here...
...is say "if we had a devastating and unexpected system error, give up immediately." Buildbot-worker seems to confirm this by throwing this exception in response:
builtins.SystemError: <method 'connect_ex' of '_socket.socket' objects> returned NULL without setting an error
internal_connect returns -1 in those devastating-and-unexpected cases--namely when an exception is to be raised--and does not ever use that to otherwise signify a legit socket error. Linux and other systems don't otherwise fall into this "res < 0" condition because errno values are positive on those systems.
So I believe the correct fix here, in sock_connect() and sock_connect_ex(), is to check "if (res == -1)" instead of "res < 0" and let all other negative error codes carry on.
If this seems like the correct approach, I can assemble a pull request, but I don't know the full ramifications of this small change, so I thought I'd report it here first.
--ryan.
iritkatriel commentedon May 14, 2023
Since Haiku is not a supported platform, I'm relabelling this from bug to feature request. I don't know how likely it is that it will be implemented though, there would need to be a core developer who cares enough about Haiku to do something non-standard for it (an assess what the implications of that may be).
encukou commentedon May 15, 2023
IMO, Python should not assume that errno codes are positive. The point of PEP-11 is to not maintain speedups/workarounds for niche platforms, not to overfit CPython to rely on quirks of the tiered platforms.
To me, this is a legitimate bug, though one that core devs won't fix alone, and might not prioritize.
Please send the PR. Considering the ramifications of the change is the reviewer's job.
erlend-aasland commentedon May 16, 2023
I agree with Petr; this definitely sounds like a bug, not a feature.
pythongh-84808: Handle errors returned by internal_connect()
pythongh-84808: Handle errors returned by internal_connect()
pythongh-84808: Handle errors returned by internal_connect()
pythongh-84808: Handle errors returned by internal_connect()
gh-84808: socket.connect_ex: Handle negative errno (GH-122304)
encukou commentedon Sep 9, 2024
Thank you
rcgordonfor the report, and @korli for the fix!