Stream.getResponse() can hang because it calls join() without any timeout:
http://hg.openjdk.java.net/jdk9/dev/jdk/file/1049321b86cb/src/java.httpclient/share/classes/java/net/http/Stream.java
...
@Override
HttpResponseImpl getResponse() throws IOException {
try {
return getResponseAsync(null).join();
} catch (Throwable e) {
Throwable t = e.getCause();
if (t instanceof IOException) {
throw (IOException)t;
}
throw e;
}
}
...
It can wait forever if a server just doesn't send anything. I also noticed that it may hang if a server send some incorrect response (the client continues waiting in this case).
It would be better if it took into account a timeout value specified for a connection, and threw HttpTimeoutException if timeout was reached.
Please see attached Timeout.java tests (timeout_test.tar) which reproduces the problem.
http://hg.openjdk.java.net/jdk9/dev/jdk/file/1049321b86cb/src/java.httpclient/share/classes/java/net/http/Stream.java
...
@Override
HttpResponseImpl getResponse() throws IOException {
try {
return getResponseAsync(null).join();
} catch (Throwable e) {
Throwable t = e.getCause();
if (t instanceof IOException) {
throw (IOException)t;
}
throw e;
}
}
...
It can wait forever if a server just doesn't send anything. I also noticed that it may hang if a server send some incorrect response (the client continues waiting in this case).
It would be better if it took into account a timeout value specified for a connection, and threw HttpTimeoutException if timeout was reached.
Please see attached Timeout.java tests (timeout_test.tar) which reproduces the problem.