(original) (raw)

diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1964,16 +1964,27 @@ BEGIN_SELECT_LOOP(s) Py_BEGIN_ALLOW_THREADS + errno = 0; timeout = internal_select_ex(s, 0, interval); - if (!timeout) { + if (!timeout && (newfd == INVALID_SOCKET)) { newfd = accept(s->sock_fd, SAS2SA(&addrbuf), &addrlen); } + else if (!timeout) { + /* newfd already points to a valid fd. This should NOT happen on a + * standard conform system. */ + SOCKETCLOSE(newfd); + timeout = 2; + } Py_END_ALLOW_THREADS if (timeout == 1) { PyErr_SetString(socket_timeout, "timed out"); return NULL; } + if (timeout == 2) { + PyErr_SetString(PyExc_OSError, "accept() loop error"); + return NULL; + } END_SELECT_LOOP(s) if (newfd == INVALID_SOCKET)