Index: Modules/socketmodule.c =================================================================== --- Modules/socketmodule.c (revision 51066) +++ Modules/socketmodule.c (working copy) @@ -1927,12 +1927,18 @@ if (res < 0 && errno == EINPROGRESS && IS_SELECTABLE(s)) { timeout = internal_select(s, 1); if (timeout == 0) { - res = connect(s->sock_fd, addr, addrlen); - if (res < 0 && errno == EISCONN) - res = 0; + /* Bug #1019808: in case of an EINPROGRESS, use + getsockopt(SO_ERROR) to get the real error. */ + socklen_t res_size = sizeof res; + (void)getsockopt(s->sock_fd, SOL_SOCKET, SO_ERROR, + &res, &res_size); + if (res == EISCONN) + res = 0; + errno = res; } - else if (timeout == -1) + else if (timeout == -1) { res = errno; /* had error */ + } else res = EWOULDBLOCK; /* timed out */ }