Java_java_net_PlainSocketImpl_socketConnect contains this code:
if (timeout <= 0) {
connect_rv = NET_Connect(fd, &sa.sa, len);
} else {
/*
* A timeout was specified. We put the socket into non-blocking
* mode, connect, and then wait for the connection to be
* established, fail, or timeout.
*/
SET_NONBLOCKING(fd);
/* no need to use NET_Connect as non-blocking */
connect_rv = connect(fd, &sa.sa, len);
/* connection not established immediately */
if (connect_rv != 0) {
socklen_t optlen;
jlong nanoTimeout = (jlong) timeout * NET_NSEC_PER_MSEC;
jlong prevNanoTime = JVM_NanoTime(env, 0);
if (errno != EINPROGRESS) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"connect failed");
JVM_NanoTime calls clock_gettime, which may theoretically clobber errno, hiding the expected EINPROGRESS error from Net_Connect.
(I hope I found the correct spot in the
This occurs in practice when running an OpenJDK 18 EA version on a current i686 (32-bit) glibc 2.34 snapshot on an older kernel that does not support clock_gettime64. We will likely paper over this in glibc before the 2.34 release, but it's still an OpenJDK source code bug because POSIX does not guarantee that successful function calls preserve errno.
glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28071
if (timeout <= 0) {
connect_rv = NET_Connect(fd, &sa.sa, len);
} else {
/*
* A timeout was specified. We put the socket into non-blocking
* mode, connect, and then wait for the connection to be
* established, fail, or timeout.
*/
SET_NONBLOCKING(fd);
/* no need to use NET_Connect as non-blocking */
connect_rv = connect(fd, &sa.sa, len);
/* connection not established immediately */
if (connect_rv != 0) {
socklen_t optlen;
jlong nanoTimeout = (jlong) timeout * NET_NSEC_PER_MSEC;
jlong prevNanoTime = JVM_NanoTime(env, 0);
if (errno != EINPROGRESS) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"connect failed");
JVM_NanoTime calls clock_gettime, which may theoretically clobber errno, hiding the expected EINPROGRESS error from Net_Connect.
(I hope I found the correct spot in the
This occurs in practice when running an OpenJDK 18 EA version on a current i686 (32-bit) glibc 2.34 snapshot on an older kernel that does not support clock_gettime64. We will likely paper over this in glibc before the 2.34 release, but it's still an OpenJDK source code bug because POSIX does not guarantee that successful function calls preserve errno.
glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28071