Marc Giger created CXF-4733:
-------------------------------

             Summary: AsyncHTTPConduit threading issue
                 Key: CXF-4733
                 URL: https://issues.apache.org/jira/browse/CXF-4733
             Project: CXF
          Issue Type: Bug
          Components: Transports
    Affects Versions: 2.7.1
            Reporter: Marc Giger


Hi,

I get the following exception

Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
 at [row,col {unknown-source}]: [1,0]
        at 
com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:677)
        at 
com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2116)
        at 
com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2022)
        at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1114)
        at 
com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1137)
        at 
org.apache.cxf.binding.soap.saaj.SAAJInInterceptor$SAAJPreInInterceptor.handleMessage(SAAJInInterceptor.java:125)
        ... 31 more

under following conditions:

- httpClientPolicy.setConnection(ConnectionType.CLOSE);
- massive parallel invocations
- SSL/TLS transport (from my analysis it seems to be independent if transport 
security is active or not but the issue can only be reproduced with SSL enabled 
and also then occurs just occasionally.)


>From my understanding the folllowing happens:

The AsyncHTTPConduit leases a pooled connection, invokes the endpoint, consumes 
the response and returns the connection to the pool. Because the client 
requested that the connection must be closed by the server 
(ConnectionType.CLOSE) the released connection is closed. A new 
AsyncHTTPConduit leases the closed connection from the pool. On first use of 
this (closed) connection an exception will be thrown that the connection is 
closed and a new one will be created (handled internally by hc). The 
AsyncHTTPConduit will be informed about the exception with the registered 
callback:

FutureCallback<Boolean> callback = new FutureCallback<Boolean>() {

                public void completed(Boolean result) {
                }
                
                public void failed(Exception ex) {
                    setException(ex);
                    inbuf.shutdown();
                    outbuf.shutdown();
                }
                public void cancelled() {
                    inbuf.shutdown();
                    outbuf.shutdown();
                }
                
            };


Here, if an exception happend, inbuf.shutdown() is called which itself sets the 
this.shutdown = true; flag in the SharedInputBuffer.

During the same time another thread? continues with a fresh connection and hits 
the 

public int read() throws IOException {
        if (this.shutdown) {
            return -1;
        }

in the same SharedInputBuffer instance which returns -1. 
This seems to be the cause for the above exception.

Just for testing purposes I replaced the statement
this.shutdown = true;
with
this.shutdown = false;

This change seems to "fix" the issue I have. I don't know how a proper fix 
should look like so I can't provide a patch. Sorry.

Thanks,

Marc

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to