This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 8680c4a16b9c8cd4902f653b3fa43597fa710148
Author: Andriy Redko <[email protected]>
AuthorDate: Sun Mar 30 10:05:34 2025 -0400

    CXF-9115: Race Condition in HttpClientHttpConduit Causes Writing Thread to 
Hang Forever (#2323)
    
    Signed-off-by: Andriy Redko <[email protected]>
    (cherry picked from commit c1d7ebb83b025481a789095caac8bdabd9555d5e)
    (cherry picked from commit 6a350a5db73c626cc0f1e54a2cd0473e923c6c7c)
    
    # Conflicts:
    #       
systests/transports/src/test/java/org/apache/cxf/systest/http/jaxws/JAXWSAsyncClientTest.java
---
 .../cxf/transport/http/HttpClientHTTPConduit.java  |  5 ++++
 .../systest/http/jaxws/JAXWSAsyncClientTest.java   | 30 +++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git 
a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java
 
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java
index 82d469e86e..1df103883a 100644
--- 
a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java
+++ 
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java
@@ -1031,6 +1031,11 @@ public class HttpClientHTTPConduit extends 
URLConnectionHTTPConduit {
                         pout.notifyAll();
                     }
                 }
+                try {
+                    close();
+                } catch (IOException e) {
+                    ex.addSuppressed(e);
+                }
                 return null;
             });
         }
diff --git 
a/systests/transports/src/test/java/org/apache/cxf/systest/http/jaxws/JAXWSAsyncClientTest.java
 
b/systests/transports/src/test/java/org/apache/cxf/systest/http/jaxws/JAXWSAsyncClientTest.java
index 40e287b441..3385489762 100644
--- 
a/systests/transports/src/test/java/org/apache/cxf/systest/http/jaxws/JAXWSAsyncClientTest.java
+++ 
b/systests/transports/src/test/java/org/apache/cxf/systest/http/jaxws/JAXWSAsyncClientTest.java
@@ -44,6 +44,7 @@ import javax.xml.transform.stream.StreamResult;
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.Response;
 import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
 import javax.xml.ws.soap.SOAPBinding;
 import javax.xml.ws.soap.SOAPFaultException;
 
@@ -68,6 +69,7 @@ import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class JAXWSAsyncClientTest  extends AbstractBusClientServerTestBase {
     static final String PORT = allocatePort(Server.class);
@@ -101,7 +103,7 @@ public class JAXWSAsyncClientTest  extends 
AbstractBusClientServerTestBase {
         public class GreeterImpl extends AbstractGreeterImpl {
             @Override
             public String greetMe(String arg) {
-                if ("timeout".equalsIgnoreCase(arg)) {
+                if ("timeout".equalsIgnoreCase(arg) || 
arg.startsWith("timeout")) {
                     try {
                         Thread.sleep(1000);
                     } catch (InterruptedException e) {
@@ -207,6 +209,32 @@ public class JAXWSAsyncClientTest  extends 
AbstractBusClientServerTestBase {
         }
     }
     
+    @Test
+    public void testTimeoutWithChunking() throws Exception {
+        // setup the feature by using JAXWS front-end API
+        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
+        factory.setAddress("http://localhost:"; + PORT + 
"/SoapContext/GreeterPort");
+        factory.setServiceClass(Greeter.class);
+        Greeter proxy = factory.create(Greeter.class);
+
+        // See please https://issues.apache.org/jira/browse/CXF-9115
+        HTTPConduit cond = (HTTPConduit)((Client)proxy).getConduit();
+        cond.getClient().setChunkingThreshold(8);
+        cond.getClient().setChunkLength(8);
+        cond.getClient().setConnectionTimeout(500);
+        cond.getClient().setReceiveTimeout(100);
+        cond.getClient().setAllowChunking(true);
+        
+        final char[] bytes = new char [64 * 1024];
+        final Random random = new Random();
+        for (int i = 0; i < bytes.length; ++i) {
+            bytes[i] = (char)(random.nextInt(26) + 'a');
+        }
+
+        final String greeting = "timeout" + new String(bytes);
+        assertThrows(WebServiceException.class, () -> proxy.greetMe(greeting));
+    }
+    
     /**
      * Not 100% reproducible but used to sporadically fail with:
      * 

Reply via email to