Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1892

Request hangs forever although sockettimeout and connecttimeout are set

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Invalid
    • Affects Version/s: 4.5.3
    • Fix Version/s: None
    • Component/s: HttpClient (classic)
    • Labels:
      None
    • Environment:
      linux

      Description

      I try to perform a head request with the http client. The client uses a proxy. The requested domain is not existing. But the proxy does not close the connection.
      But what I dont understand, is why the client hangs forever and non of the configured timeouts activates and aborts the request.
      Her is my example code:

      httpResponse = proxiedHttpClient.execute(
              new HttpHead("https://iAmNotExisting.com/dummy.jpg"))
      

      Here is my code for configuring the client:

      final String hostName = "proxyhost";
      final int port = 1234;
      final HttpClientBuilder clientBuilder = HttpClientBuilder.create();
      clientBuilder.useSystemProperties();
      clientBuilder.setDefaultRequestConfig(RequestConfig.custom()
            .setCookieSpec(STANDARD)
            .setConnectionRequestTimeout((int) Duration.ofSeconds(1).toMillis())
            .setSocketTimeout((int) Duration.ofSeconds(1).toMillis())
            .setConnectTimeout((int) Duration.ofSeconds(1).toMillis()).build());
      clientBuilder.setProxy(new HttpHost(hostName, port));
      clientBuilder.setDefaultCredentialsProvider(
      getCredentialsProvider(hostName, port, "proxyuser", proxypassword));
      clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
      return clientBuilder.build();
      

      Here is a threaddump from the hanging thread:

      java.lang.Thread.State: RUNNABLE
      	at java.net.SocketInputStream.socketRead0(Native Method)
      	at java.net.SocketInputStream.socketRead(Unknown Source)
      	at java.net.SocketInputStream.read(Unknown Source)
      	at java.net.SocketInputStream.read(Unknown Source)
      	at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
      	at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
      	at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:282)
      	at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138)
      	at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56)
      	at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)
      	at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163)
      	at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:165)
      	at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)
      	at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
      	at org.apache.http.impl.execchain.MainClientExec.createTunnelToTarget(MainClientExec.java:473)
      	at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:398)
      	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
      	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
      	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
      	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
      	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
      	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
      	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
      	at de.feed.common.job.HttpClientTestJob.execute(HttpClientTestJob.java:47)
      

      Here is the request performed with curl:

      curl -X HEAD --proxy "proxyuser:proxypassword@proxyhost:1234"  "https://iAmNotExisting.com/dummy.jpg" --verbose
      * About to connect() to proxy proxyhost port (#0)
      *   Trying 15.112.12.32...
      * Connected to proxyhost (15.112.12.32) port 1234 (#0)
      * Establish HTTP proxy tunnel to iAmNotExisting.com:443
      * Proxy auth using Basic with user 'proxyuser'
      > CONNECT iAmNotExisting.com:443 HTTP/1.1
      > Host: iAmNotExisting.com:443
      > Proxy-Authorization: Basic blablub=
      > User-Agent: curl/7.29.0
      > Proxy-Connection: Keep-Alive
      > 
      * Operation timed out after 300314 milliseconds with 0 out of 0 bytes received
      * Closing connection 0
      curl: (28) Operation timed out after 300314 milliseconds with 0 out of 0 bytes received
      

      I think, this is either a bug, because the socket timeout does not work or that a request timeout would be needed if the socket timeout is not intended for this use case

      The behavior of the proxy could be caused, because it is a keep-alive session.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              chrisf Christian F
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: