[ 
https://issues.apache.org/jira/browse/CXF-9095?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Freeman Yue Fang reassigned CXF-9095:
-------------------------------------

    Assignee: Freeman Yue Fang

> Connection Leak in HttpClientWrappedOutputStream due to Unreleased Resources 
> on IOException
> -------------------------------------------------------------------------------------------
>
>                 Key: CXF-9095
>                 URL: https://issues.apache.org/jira/browse/CXF-9095
>             Project: CXF
>          Issue Type: Bug
>          Components: Transports
>    Affects Versions: 4.0.1, 4.0.2, 4.0.3, 4.0.4, 4.0.5, 4.0.6
>         Environment: - Apache CXF Version: 4.0.6
> - Java Version: OpenJDK 17.0.12
> - Operating System: Ubuntu 18.04 AMD 64
>            Reporter: suxuan
>            Assignee: Freeman Yue Fang
>            Priority: Major
>         Attachments: 2025-01-07 15.26.40.png, 2025-01-07 15.27.19.png
>
>
> When the `close` method of the parent class 
> `org.apache.cxf.transport.http.HTTPConduit.WrappedOutputStream` is called, a 
> timeout occurs at line 1420, resulting in an `IOException`. This exception is 
> caught at line 1428 and subsequently rethrown to the upper layer.
> The upper layer, specifically the `close` method in 
> `org.apache.cxf.transport.http.HttpClientHTTPConduit.HttpClientWrappedOutputStream`,
>  does not properly handle the exception. As a result, the `pout` resource 
> (which corresponds to the socket for writing) is not released, leading to a 
> connection leak.
> {*}{color:#FF0000}The Java exception stack trace is as follows{color}{*}:
>  Caused by: java.net.http.HttpTimeoutException: HttpTimeoutException invoking 
> [https://reporting.api.bingads.microsoft.com/Reporting/v13/GenerateReport/Poll:]
>  Timeout
> at 
> java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native
>  Method)
> at 
> java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
> at 
> java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> at 
> java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
> at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
> at 
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:1452)
> at 
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1433)
> at 
> org.apache.cxf.transport.http.HttpClientHTTPConduit$HttpClientWrappedOutputStream.close(HttpClientHTTPConduit.java:824)
> at 
> org.apache.cxf.io.AbstractWrappedOutputStream.close(AbstractWrappedOutputStream.java:77)
> at 
> org.apache.cxf.io.AbstractWrappedOutputStream.close(AbstractWrappedOutputStream.java:77)
> at 
> org.apache.cxf.io.AbstractThresholdOutputStream.close(AbstractThresholdOutputStream.java:102)
> at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
> at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:717)
> at 
> org.apache.cxf.transport.http.HttpClientHTTPConduit.close(HttpClientHTTPConduit.java:261)
> at 
> org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:63)
> at 
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
> at 
> org.apache.cxf.jaxrs.client.AbstractClient.doRunInterceptorChain(AbstractClient.java:717)
> at 
> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1085)
> ... 17 more
> Caused by: java.net.http.HttpTimeoutException: Timeout
> at 
> org.apache.cxf.transport.http.HttpClientHTTPConduit$HttpClientWrappedOutputStream.getResponse(HttpClientHTTPConduit.java:1074)
> at 
> org.apache.cxf.transport.http.HttpClientHTTPConduit$HttpClientWrappedOutputStream.getResponseCode(HttpClientHTTPConduit.java:1081)
> at 
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.doProcessResponseCode(HTTPConduit.java:1653)
> at 
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1684)
> at 
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1626)
> at 
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1420)
> ... 28 more
> Caused by: java.util.concurrent.TimeoutException
> at 
> java.base/java.util.concurrent.CompletableFuture.timedGet(CompletableFuture.java:1960)
> at 
> java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2095)
> at 
> org.apache.cxf.transport.http.HttpClientHTTPConduit$HttpClientWrappedOutputStream.getResponse(HttpClientHTTPConduit.java:1052)
> ... 33 more
> As the service runs, the number of TCP connections in the CLOSE_WAIT state in 
> the system continues to increase until no connections are available.
> Here is a suggested code snippet:
> {code:java}
>         @Override
>         public void close() throws IOException {
>             try {
>                 try {
>                     super.close();
>                 } finally {
>                     if (pout != null) {
>                         pout.close();
>                         pout = null;
>                     }
>                 }
>             } finally {
>                 if (publisher != null) {
>                     publisher.close();
>                     publisher = null;
>                 }
>                 request = null;
>                 subscribers = null;
>             }
>         }
> {code}



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

Reply via email to