eclipse-ee4j / eclipse-ee4j/jersey

Random "Stream closed" exception when using basicBuilder.nonPreemptive

Open
#4,011 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

I'm using JUnit with JMH benchmarks, TestContainers and jersey-client to test some application. When JMH the benchmark uses hundreds of threads to create some load, around 1% of invocations end with the exception cause by `java.io.IOException: Stream closed.` or `Socket closed`.

Configuration is this:

```
@Setup(Level.Trial)
public void initClient() {
LOG.debug("initClient()");
final TestProperties testCfg = new TestProperties();
final ClientConfig clientCfg = new ClientConfig();

clientCfg.property(ClientProperties.CONNECT_TIMEOUT, 1000);
clientCfg.property(ClientProperties.READ_TIMEOUT, 60000);
clientCfg.property(ClientProperties.FOLLOW_REDIRECTS, false);

final Builder authFeature = HttpAuthenticationFeature.basicBuilder().nonPreemptive()
.credentials(testCfg.getFlexibeeUsername(), testCfg.getFlexibeePassword());
clientCfg.register(authFeature.build());

this.client = ClientBuilder.newClient(clientCfg);
}

@TearDown(Level.Trial)
public void closeClient() {
LOG.debug("closeClient()");
if (this.client != null) {
this.client.close();
}
}
```

If I replace the `HttpAuthenticationFeature.basicBuilder().nonPreemptive()` with the `HttpAuthenticationFeature.universalBuilder()`, tests are successful.

One of the stacktraces, sometimes the IOException is thrown from response.getEntity, sometimes from response.close or response.hasEntity:

```
javax.ws.rs.ProcessingException: Error closing message content input stream.
at org.glassfish.jersey.message.internal.EntityInputStream.close(EntityInputStream.java:162)
at org.glassfish.jersey.message.internal.InboundMessageContext$EntityContent.close(InboundMessageContext.java:156)
at org.glassfish.jersey.message.internal.InboundMessageContext.close(InboundMessageContext.java:939)
at org.glassfish.jersey.client.InboundJaxrsResponse.close(InboundJaxrsResponse.java:167)
at xxx.test.performance.connpoolinfo.ConnectionPoolInfoPerformanceBenchmark.closeCompanyDS(ConnectionPoolInfoPerformanceBenchmark.java:57)
at xxx.test.performance.connpoolinfo.ConnectionPoolInfoPerformanceBenchmark.benchmarkUrl(ConnectionPoolInfoPerformanceBenchmark.java:36)
at xxx.test.performance.connpoolinfo.generated.ConnectionPoolInfoPerformanceBenchmark_benchmarkUrl_jmhTest.benchmarkUrl_AverageTime(ConnectionPoolInfoPerformanceBenchmark_benchmarkUrl_jmhTest.java:352)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:453)
at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:437)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Stream closed.
at java.net.AbstractPlainSocketImpl.available(AbstractPlainSocketImpl.java:470)
at java.net.SocketInputStream.available(SocketInputStream.java:259)
at java.io.BufferedInputStream.available(BufferedInputStream.java:410)
at sun.net.www.MeteredStream.available(MeteredStream.java:170)
at sun.net.www.http.KeepAliveStream.close(KeepAliveStream.java:85)
at java.io.FilterInputStream.close(FilterInputStream.java:181)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.close(HttpURLConnection.java:3517)
at org.glassfish.jersey.client.internal.HttpUrlConnector$2.close(HttpUrlConnector.java:247)
at org.glassfish.jersey.message.internal.EntityInputStream.close(EntityInputStream.java:159)
... 17 more
```

Maybe this issue is related with #3526 or #3486 , but I'm not sure.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.