ADDITIONAL SYSTEM INFORMATION :
Could reproduce on:
Windows 7 jdk1.8.0_091, jdk1.8.0_111 and jdk1.8.0_172
Could not reproduce on:
Debian 9.3 open-jdk1.8.0_171
ArchLinux open-jdk1.8.0_172
A DESCRIPTION OF THE PROBLEM :
Unread content of Socket's InputStream should be readable even after the close of the socket. This is the case but when writing something in the output stream before reading, it interferes and makes a read error when trying to read the remaining bit of information. The problem occurs everytime I run the code, it is pretty consistent.
REGRESSION : Last worked in version 8u162
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the specified test case
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
1
2
The writing error may or may not appear, the important part is that 2 should be read.
ACTUAL -
1
java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.net.SocketInputStream.read(SocketInputStream.java:224)
at SocketTTest.lambda$main$0(SocketTTest.java:45)
at java.lang.Thread.run(Thread.java:748)
Error reading
---------- BEGIN SOURCE ----------
public static void main(String[] args) throws Throwable
{
new Thread(() -> {
try
{
ServerSocket serverSocket = new ServerSocket(5555);
while(true)
{
//keep listening
Socket socket = serverSocket.accept();
InputStream in = socket.getInputStream();
System.out.println(in.read());
Thread.sleep(2000);
try
{
socket.getOutputStream().write(3);
}
catch(Throwable ex)
{
System.out.println("Error writing");
ex.printStackTrace();
}
System.out.println(in.read());
in.close();
socket.close();
System.exit(0);
}
}
catch(Throwable ex)
{
System.out.println("Error reading");
ex.printStackTrace();
}
}).start();
Thread.sleep(100);
Socket socket = new Socket("localhost", 5555);
OutputStream out = socket.getOutputStream();
out.write(1);
out.write(2);
out.close();
socket.close();
Object object = new Object();
synchronized(object)
{
object.wait();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Didn't find one, would love to have one
FREQUENCY : always