diff --git a/Misc/ACKS b/Misc/ACKS index 3e53429bf23..311259f1e5f 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -832,6 +832,7 @@ Lawrence Kesteloot Garvit Khatri Vivek Khera Dhiru Kholia +Artem Khramov Akshit Khurana Sanyam Khurana Mads Kiilerich diff --git a/Misc/NEWS.d/next/Library/2019-08-14-21-41-07.bpo-37811.d1xYj7.rst b/Misc/NEWS.d/next/Library/2019-08-14-21-41-07.bpo-37811.d1xYj7.rst new file mode 100644 index 00000000000..662e7dc4100 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-08-14-21-41-07.bpo-37811.d1xYj7.rst @@ -0,0 +1,4 @@ +Fix ``socket`` module's ``socket.connect(address)`` function being unable to +establish connection in case of interrupted system call. The problem was +observed on all OSes which ``poll(2)`` system call can take only +non-negative integers and -1 as a timeout value. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 0470f387e3b..910e2bdd131 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -780,6 +780,17 @@ internal_select(PySocketSockObject *s, int writing, _PyTime_t interval, ms = _PyTime_AsMilliseconds(interval, _PyTime_ROUND_CEILING); assert(ms <= INT_MAX); + /* On some OSes, typically BSD-based ones, the timeout parameter of the + poll() syscall, when negative, must be exactly INFTIM, where defined, + or -1. See issue 37811. */ + if (ms < 0) { +#ifdef INFTIM + ms = INFTIM; +#else + ms = -1; +#endif + } + Py_BEGIN_ALLOW_THREADS; n = poll(&pollfd, 1, (int)ms); Py_END_ALLOW_THREADS;