Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8156710

HttpTimeoutException should be thrown if server doesn't respond

XMLWordPrintable

    • b119
    • Verified

      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.

            asmotrak Artem Smotrakov
            asmotrak Artem Smotrakov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: