[ 
https://issues.apache.org/jira/browse/CXF-9135?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17950734#comment-17950734
 ] 

Vadim Beilin commented on CXF-9135:
-----------------------------------

I did a bit more investigation, and this seems to be a threading issue.

Both HttpClientSizedBodyPublisher.contentLength() and 
HttpClientSizedBodyPublisher.subscribe() are called from HttpClient's worker 
thread, (initiated by 
[sendAsync|https://github.com/apache/cxf/blob/main/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java#L1026]),
 and both these methods require {{stream.pout}} not to be null.

In 
[HttpClientWrappedOutputStream.close()|https://github.com/apache/cxf/blob/main/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java#L823]
{code:java}
        public void close() throws IOException {
            try {
                super.close();  // <-- A
            } finally {
                if (pout != null) {
                    try {
                        pout.close();
                    } catch (IOException e) {
                        logStackTrace(e);
                    }
                    pout = null; // <-- B
                }
{code}
line A is where asyncSend is called and sending starts.
line B is where {{pout}} is reset – after this HttpClientSizedBodyPublisher 
can't work correctly.
Looks like the code does not take into account that not only waiting for the 
response but preparing the request as well is happening in a worker thread.
I checked that adding a slight delay after line A makes the second async call 
in my example complete succesfully.

> Second async javax call fails with allowChunking=false
> ------------------------------------------------------
>
>                 Key: CXF-9135
>                 URL: https://issues.apache.org/jira/browse/CXF-9135
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-WS Runtime
>    Affects Versions: 4.1.1
>         Environment: Java 17
>            Reporter: Vadim Beilin
>            Priority: Major
>         Attachments: ShowBug.java
>
>
> The second call to an asynchronous web method is failing when using the JDK 
> HttpClient-based conduit and allowChunking set to false.
>  
> Logs show that the while the first request has correct conetnt-length, the 
> second request has Transfer-encoding: chunked, and the body is not sent at 
> all. Here are 3 requests received by the server (WSDL and two web methods):
> {noformat}
> ID: 1
> Address: http://localhost:12345/Service?wsdl
> Http-Method: GET
> Content-Type: 
> Headers: {Accept=[*/*], connection=[Upgrade, HTTP2-Settings], 
> Content-Length=[0], Content-Type=[null], Host=[localhost:12345], 
> HTTP2-Settings=[AAEAAEAAAAIAAAABAAMAAABkAAQBAAAAAAUAAEAA], Upgrade=[h2c], 
> User-Agent=[Apache-CXF/4.1.1]}
> {noformat}
> {noformat}
> ID: 2
> Address: http://localhost:12345/Service
> Encoding: UTF-8
> Http-Method: POST
> Content-Type: text/xml; charset=UTF-8
> Headers: {Accept=[*/*], connection=[Upgrade, HTTP2-Settings], 
> Content-Length=[152], content-type=[text/xml; charset=UTF-8], 
> Host=[localhost:12345], 
> HTTP2-Settings=[AAEAAEAAAAIAAAABAAMAAABkAAQBAAAAAAUAAEAA], SOAPAction=[""], 
> Upgrade=[h2c], User-Agent=[Apache-CXF/4.1.1]}
> Payload: <soap:Envelope 
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";><soap:Body><respond 
> xmlns="http://test";>blah</respond></soap:Body></soap:Envelope>
> {noformat}
> {noformat}
> ID: 3
> Address: http://localhost:12345/Service
> Encoding: UTF-8
> Http-Method: POST
> Content-Type: text/xml; charset=UTF-8
> Headers: {Accept=[*/*], connection=[Upgrade, HTTP2-Settings], 
> content-type=[text/xml; charset=UTF-8], Host=[localhost:12345], 
> HTTP2-Settings=[AAEAAEAAAAIAAAABAAMAAABkAAQBAAAAAAUAAEAA], SOAPAction=[""], 
> transfer-encoding=[chunked], Upgrade=[h2c], User-Agent=[Apache-CXF/4.1.1]}
> {noformat}
> I'm attaching a test class that demonstrates the issue.
> For the failure to happen, we need 
> * to use the new default HttpClient-based conduit (URLConnection-based 
> conduit works)
>  * {{allowChunking}} to be set to false (not set or set to true works)
>  * an asyncronous service method to be used (synchronous method works)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to