Cedric Tabin created CXF-9080:
---------------------------------
Summary: ClientProxy concurrency close/destroy
Key: CXF-9080
URL: https://issues.apache.org/jira/browse/CXF-9080
Project: CXF
Issue Type: Bug
Components: Core
Affects Versions: 4.0.5
Reporter: Cedric Tabin
Hello,
There is a GC issue to do a missing reference on the `ClientProxy` that is
holding the `ClientImpl`. Here is the code snippet we use:
{code:java}
Object port = getPort();
try(ClientImpl client = (ClientImpl)ClientProxy.getClient(port)) {
//...
}
{code}
The problem resides in the method `ClientProxy.getClient` because the latter
creates a `ClientProxy` instance and returns its internal `ClientImpl` but
there is no more reference to the `ClientProxy` after the method returns... and
under heavy load, we might hit either a Connection closed or even the following
error (hit by chance after [PR2140|https://github.com/apache/cxf/pull/2140]):
{noformat}
Caused by: org.apache.cxf.interceptor.Fault: Could not send Message.
at
org.apache.cxf.transport.http.HttpClientHTTPConduit$HttpClientWrappedOutputStream.isConnectionAttemptCompleted(HttpClientHTTPConduit.java:780)
at
org.apache.cxf.transport.http.HttpClientHTTPConduit$HttpClientPipedOutputStream.canWrite(HttpClientHTTPConduit.java:540)
at
org.apache.cxf.transport.http.HttpClientHTTPConduit$HttpClientPipedOutputStream.write(HttpClientHTTPConduit.java:550)
at
org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:51)
at
org.apache.cxf.io.AbstractThresholdOutputStream.write(AbstractThresholdOutputStream.java:69)
at
java.base/java.io.ByteArrayOutputStream.writeTo(ByteArrayOutputStream.java:170)
at
ch.swissdec.jaxws.net.BufferedOutputStreamWrapper.sendBufferedContent(BufferedOutputStreamWrapper.java:37)
at
ch.swissdec.jaxws.net.BufferedOutputStreamWrapper.flush(BufferedOutputStreamWrapper.java:27)
at
org.apache.cxf.transport.http.HttpClientHTTPConduit.close(HttpClientHTTPConduit.java:253)
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.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:441)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:356)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:314)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:334)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:320)
... 14 more
Caused by: java.io.IOException: shutdownNow
at
java.net.http/jdk.internal.net.http.HttpClientImpl.shutdownNow(HttpClientImpl.java:622)
at
java.net.http/jdk.internal.net.http.HttpClientFacade.shutdownNow(HttpClientFacade.java:182)
at
org.apache.cxf.transport.http.HttpClientHTTPConduit$RefCount.lambda$release$0(HttpClientHTTPConduit.java:143)
at
java.base/java.security.AccessController.doPrivileged(AccessController.java:571)
at
org.apache.cxf.transport.http.HttpClientHTTPConduit$RefCount.release(HttpClientHTTPConduit.java:138)
at
org.apache.cxf.transport.http.HttpClientHTTPConduit.close(HttpClientHTTPConduit.java:267)
at
org.apache.cxf.endpoint.AbstractConduitSelector.close(AbstractConduitSelector.java:77)
at org.apache.cxf.endpoint.ClientImpl.destroy(ClientImpl.java:177)
at org.apache.cxf.frontend.ClientProxy.close(ClientProxy.java:52)
at org.apache.cxf.jaxws.JaxWsClientProxy.close(JaxWsClientProxy.java:84)
at org.apache.cxf.frontend.ClientProxy.finalize(ClientProxy.java:123)
at java.base/java.lang.System$2.invokeFinalize(System.java:2384)
at java.base/java.lang.ref.Finalizer.runFinalizer(Finalizer.java:96)
at
java.base/java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:174)
{noformat}
As a workaround, here is the code snipped we use now:
{code:java}
Object port = getPort();
ClientProxy proxy = ((ClientProxy)Proxy.getInvocationHandler(port));
try(ClientImpl client = (ClientImpl)proxy.getClient()) {
//...
} finally {
proxy.close();
}
{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)