Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-5590

On socket timeout an IllegalStateException is thrown

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.7.10
    • Fix Version/s: 2.7.11, 3.0
    • Component/s: Transports
    • Labels:
      None
    • Environment:

      Windows 7 64 bits & RedHat 6.4

    • Estimated Complexity:
      Unknown

      Description

      When a socket timeout occurs during a Jaxrs async request (I do not have done the test on synchronous request) the following exception is thrown :

      javax.ws.rs.client.ClientException: javax.ws.rs.client.ClientException: java.lang.IllegalStateException: IllegalStateException invoking http://localhost:50324/geoloc?ip=10.1.1.2&lang=en: Already connected
      at org.apache.cxf.jaxrs.client.JaxrsClientCallback.handleException(JaxrsClientCallback.java:90) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.WebClient.handleAsyncResponse(WebClient.java:988) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.WebClient.access$100(WebClient.java:80) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.WebClient$ClientAsyncResponseInterceptor.handleMessage(WebClient.java:1265) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) ~[cxf-api-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.ClientMessageObserver.onMessage(ClientMessageObserver.java:56) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream$1.run(HTTPConduit.java:1138) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:428) ~[cxf-api-2.7.10.jar:2.7.10]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_25]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_25]
      at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:353) ~[cxf-api-2.7.10.jar:2.7.10]
      at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
      Caused by: javax.ws.rs.client.ClientException: java.lang.IllegalStateException: IllegalStateException invoking http://localhost:50324/geoloc?ip=10.1.1.2&lang=en: Already connected
      at org.apache.cxf.jaxrs.client.WebClient.handleAsyncResponse(WebClient.java:984) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      ... 10 common frames omitted
      Caused by: java.lang.IllegalStateException: IllegalStateException invoking http://localhost:50324/geoloc?ip=10.1.1.2&lang=en: Already connected
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_25]
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_25]
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_25]
      at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_25]
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:1346) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1335) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) ~[cxf-api-2.7.10.jar:2.7.10]
      at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:628) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.endpoint.AbstractConduitSelector.complete(AbstractConduitSelector.java:185) ~[cxf-api-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.AbstractClient.preProcessResult(AbstractClient.java:556) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.WebClient.handleAsyncResponse(WebClient.java:979) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      ... 10 common frames omitted
      Caused by: java.lang.IllegalStateException: Already connected
      at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:2748) ~[na:1.7.0_25]
      at org.apache.cxf.transport.http.Headers.setProtocolHeadersInConnection(Headers.java:273) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.transport.http.URLConnectionHTTPConduit$URLConnectionWrappedOutputStream.setProtocolHeaders(URLConnectionHTTPConduit.java:213) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleHeadersTrustCaching(HTTPConduit.java:1267) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1306) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      ... 15 common frames omitted

      -----------------------------------------------------------

      This exception is due to the work done during the call of handleHeadersTrustCaching() in HTTPConduit.
      The following method are called :
      1/ URLConnectionHTTPConduit$URLConnectionWrappedOutputStream.setProtocolHeaders()
      2/ Headers.setProtocolHeadersInConnection(HttpURLConnection connection)

      This last method failed on the following line :
      connection.setRequestProperty(HttpHeaderHelper.CONTENT_TYPE, ct);
      because connection is in "socket timeout state".

      What I have found is :
      1/ The SocketTimeoutException is stored on connection field of :
      org.apache.cxf.transport.http.URLConnectionHTTPConduit$URLConnectionWrappedOutputStream
      2/ This type of connection field is : HttpURLConnection
      3/ the exception SocketTimeout is stored in rememberedException
      4/ The only way (except unprotecting this private field) in order to access rememberedException is to call getInputStream which throw the rememberedException if present

      What could be done is to call getInputStream() just before calling handleHeadersTrustCaching method, if an exception is thrown handleHeadersTrustCaching will not be called. It's not a beautifull fix, but it works for this case.
      Another solution could be the storage of the SocketTimeoutException during the processing of the request but it could have a bigger impact

      You will find a patch for version 2.7.10 with the usage of getInputStream. The following exception is thrown with the patch :

      ---------------------------------------------------

      javax.ws.rs.client.ClientException: javax.ws.rs.client.ClientException: java.net.SocketTimeoutException: Read timed out
      at org.apache.cxf.jaxrs.client.JaxrsClientCallback.handleException(JaxrsClientCallback.java:90) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.WebClient.handleAsyncResponse(WebClient.java:988) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.WebClient.access$100(WebClient.java:80) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.WebClient$ClientAsyncResponseInterceptor.handleMessage(WebClient.java:1265) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) ~[cxf-api-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.ClientMessageObserver.onMessage(ClientMessageObserver.java:56) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream$1.run(HTTPConduit.java:1138) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:428) ~[cxf-api-2.7.10.jar:2.7.10]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_25]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_25]
      at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:353) ~[cxf-api-2.7.10.jar:2.7.10]
      at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
      Caused by: javax.ws.rs.client.ClientException: java.net.SocketTimeoutException: Read timed out
      at org.apache.cxf.jaxrs.client.AbstractClient.checkClientException(AbstractClient.java:575) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.AbstractClient.preProcessResult(AbstractClient.java:557) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.WebClient.handleAsyncResponse(WebClient.java:979) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      ... 10 common frames omitted
      Caused by: java.net.SocketTimeoutException: Read timed out
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_25]
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_25]
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_25]
      at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_25]
      at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1674) ~[na:1.7.0_25]
      at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1672) ~[na:1.7.0_25]
      at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_25]
      at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1670) ~[na:1.7.0_25]
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1243) ~[na:1.7.0_25]
      at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468) ~[na:1.7.0_25]
      at org.apache.cxf.transport.http.URLConnectionHTTPConduit$URLConnectionWrappedOutputStream.getResponseCode(URLConnectionHTTPConduit.java:266) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1548) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream$1.run(HTTPConduit.java:1129) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      ... 5 common frames omitted
      Caused by: java.net.SocketTimeoutException: Read timed out
      at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.7.0_25]
      at java.net.SocketInputStream.read(SocketInputStream.java:150) ~[na:1.7.0_25]
      at java.net.SocketInputStream.read(SocketInputStream.java:121) ~[na:1.7.0_25]
      at java.io.BufferedInputStream.fill(BufferedInputStream.java:235) ~[na:1.7.0_25]
      at java.io.BufferedInputStream.read1(BufferedInputStream.java:275) ~[na:1.7.0_25]
      at java.io.BufferedInputStream.read(BufferedInputStream.java:334) ~[na:1.7.0_25]
      at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:633) ~[na:1.7.0_25]
      at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:579) ~[na:1.7.0_25]
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1322) ~[na:1.7.0_25]
      at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468) ~[na:1.7.0_25]
      at org.apache.cxf.transport.http.URLConnectionHTTPConduit$URLConnectionWrappedOutputStream.getResponseCode(URLConnectionHTTPConduit.java:266) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.transport.http.URLConnectionHTTPConduit$URLConnectionWrappedOutputStream.getInputStream(URLConnectionHTTPConduit.java:237) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1309) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:50) ~[cxf-api-2.7.10.jar:2.7.10]
      at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:223) ~[cxf-api-2.7.10.jar:2.7.10]
      at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) ~[cxf-api-2.7.10.jar:2.7.10]
      at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:628) ~[cxf-rt-transports-http-2.7.10_PATCH.jar:2.7.10.PATCH]
      at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) ~[cxf-api-2.7.10.jar:2.7.10]
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) ~[cxf-api-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.AbstractClient.doRunInterceptorChain(AbstractClient.java:634) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.WebClient.doInvokeAsync(WebClient.java:942) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.WebClient.doInvokeAsyncCallback(WebClient.java:914) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.WebClient$AsyncInvokerImpl.method(WebClient.java:1438) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at org.apache.cxf.jaxrs.client.WebClient$AsyncInvokerImpl.get(WebClient.java:1307) ~[cxf-rt-frontend-jaxrs-2.7.10.jar:2.7.10]
      at com.capgemini.common.ws.client.subsystem.AsyncService.executeGet(AsyncService.java:74) ~[classes/:na]
      at com.capgemini.opentv.enabler.geoloc.rest.client.GeolocUtils.getGeolocAsync(GeolocUtils.java:91) ~[classes/:na]
      at com.capgemini.opentv.mediation.mup.application.module.impl.async.GeolocAsyncRequestLauncher.launchAsyncTask(GeolocAsyncRequestLauncher.java:58) ~[classes/:na]
      at com.capgemini.common.async.AbstractAsyncWorkflow.nextStep(AbstractAsyncWorkflow.java:140) ~[classes/:na]
      at com.capgemini.common.async.WorkflowExecutor.run(WorkflowExecutor.java:44) ~[classes/:na]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_25]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_25]
      ... 1 common frames omitted

        Attachments

        1. HTTPConduit.java.patch
          0.6 kB
          Anthony Communier

          Activity

            People

            • Assignee:
              sergey_beryozkin Sergey Beryozkin
              Reporter:
              anthonyC Anthony Communier
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: