-
Bug
-
Resolution: Fixed
-
P3
-
11
FULL PRODUCT VERSION :
openjdk 11-ea 2018-09-18
OpenJDK Runtime Environment (build 11-ea+7)
OpenJDK 64-Bit Server VM (build 11-ea+7, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.15063]
A DESCRIPTION OF THE PROBLEM :
Calling connect with a timeout on a SocketChannel's socket() when the address is a non-existing endpoint never fails.
And what is worse, the socket's state ends up as "connected".
If the endpoint does exist, but is not established within the timeout, the method correctly fails with java.net.SocketTimeout exception.
REGRESSION. Last worked in version 10
ADDITIONAL REGRESSION INFORMATION:
java 10 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided test class with Java11-ea+7
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
That the connect() call fails with a java.net.ConnectException and the message "this should happen: Connection refused: no further information" appears on stdout.
ACTUAL -
The connect() call does NOT fail with the expected java.net.ConnectException. And the socket's isConnected() method returns true but fails with an exception when accessing the output stream (correctly reporting that the socket is NOT connected):
java.io.IOException: A request to send or receive data was disallowed because the socket is not connected
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.SocketChannel;
public class Sockets {
public static void main(String[] args) throws IOException {
SocketChannel sc = SocketChannel.open();
Socket socket = sc.socket();
try {
InetSocketAddress addr = new InetSocketAddress("localhost", 65535); // should point to non-existing endpoint
socket.connect(addr, 5000);
} catch (IOException e) {
System.out.println("this should happen: " + e.getMessage());
System.exit(0);
}
System.out.println("socket is connected: " + socket.isConnected());
if (socket.isConnected()) {
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
dos.writeInt(42);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Call connect() without a timeout - either directly on the SocketChannel or on its socket(). But that is not really an option if I need to specify the timeout...
openjdk 11-ea 2018-09-18
OpenJDK Runtime Environment (build 11-ea+7)
OpenJDK 64-Bit Server VM (build 11-ea+7, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.15063]
A DESCRIPTION OF THE PROBLEM :
Calling connect with a timeout on a SocketChannel's socket() when the address is a non-existing endpoint never fails.
And what is worse, the socket's state ends up as "connected".
If the endpoint does exist, but is not established within the timeout, the method correctly fails with java.net.SocketTimeout exception.
REGRESSION. Last worked in version 10
ADDITIONAL REGRESSION INFORMATION:
java 10 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided test class with Java11-ea+7
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
That the connect() call fails with a java.net.ConnectException and the message "this should happen: Connection refused: no further information" appears on stdout.
ACTUAL -
The connect() call does NOT fail with the expected java.net.ConnectException. And the socket's isConnected() method returns true but fails with an exception when accessing the output stream (correctly reporting that the socket is NOT connected):
java.io.IOException: A request to send or receive data was disallowed because the socket is not connected
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.SocketChannel;
public class Sockets {
public static void main(String[] args) throws IOException {
SocketChannel sc = SocketChannel.open();
Socket socket = sc.socket();
try {
InetSocketAddress addr = new InetSocketAddress("localhost", 65535); // should point to non-existing endpoint
socket.connect(addr, 5000);
} catch (IOException e) {
System.out.println("this should happen: " + e.getMessage());
System.exit(0);
}
System.out.println("socket is connected: " + socket.isConnected());
if (socket.isConnected()) {
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
dos.writeInt(42);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Call connect() without a timeout - either directly on the SocketChannel or on its socket(). But that is not really an option if I need to specify the timeout...
- relates to
-
JDK-8201588 should check for cases when Net.poll returns POLLHUP, POLLERR or POLLNVAL
-
- Closed
-