eclipse-ee4j / eclipse-ee4j/jersey
Client with JettyConnector fails on chained calls
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
## Affected Versions
Reproduced on the following versions of Jersey: 3.0.9, 3.0.10, 3.1.1.
## Setup
Jersey HTTP client is created like this:
```java
ClientConfig config = new ClientConfig();
config.connectorProvider(new JettyConnectorProvider());
Client client = ClientBuilder.newBuilder().withConfig(config).build();
```
## Problem Description
The following call asynchronously and sequentially invokes two URLs on the same server (URLs may be the same or different) :
```java
WebTarget target = client.target(someUrl);
target.request().rx()
.get()
.thenApply(r -> target.request().get())
.toCompletableFuture()
.get();
```
It blocks for 30 seconds, and then throws a timeout exception shown below. The problem DOESN'T happen if _either_ of these is true:
* `JettyConnectorProvider` is not in use (i.e. with the default transport)
* When the chained URL and the initial URL are on different hosts (I assume cause it hits a different Jetty connection pool)
* If I change "thenApply" to "thenCompose" (maybe because `thenCompose` is itself invoked asynchronously) :
```java
target.request().rx()
.get()
.thenCompose(r -> CompletableFuture.supplyAsync(() -> target.request().get()))
.toCompletableFuture()
.get();
```
The full runnable test is available in the Bootique Jersey project: https://github.com/bootique/bootique-jersey/blob/master/bootique-jersey-jakarta-client-jetty/src/test/java/io/bootique/jersey/client/jetty/JerseyClientJettyModuleIT.java#L94 Bootique itself is incidental to the problem. The cause is in the combination of Jersey HttpClient and Jetty transport.
```
java.util.concurrent.ExecutionException: jakarta.ws.rs.ProcessingException: java.util.concurrent.TimeoutException: Idle timeout 30000 ms
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
at io.bootique.jersey.client.jetty.JerseyClientJettyModuleIT.testGetRxThenApply(JerseyClientJettyModuleIT.java:105)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
at ...
Caused by: jakarta.ws.rs.ProcessingException: java.util.concurrent.TimeoutException: Idle timeout 30000 ms
at org.glassfish.jersey.jetty.connector.JettyConnector.apply(JettyConnector.java:289)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:300)
at org.glassfish.jersey.client.JerseyInvocation.lambda$invoke$0(JerseyInvocation.java:662)
at org.glassfish.jersey.client.JerseyInvocation.call(JerseyInvocation.java:697)
at org.glassfish.jersey.client.JerseyInvocation.lambda$runInScope$3(JerseyInvocation.java:691)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:205)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:390)
at org.glassfish.jersey.client.JerseyInvocation.runInScope(JerseyInvocation.java:691)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:661)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:413)
at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:313)
at io.bootique.jersey.client.jetty.JerseyClientJettyModuleIT.lambda$testGetRxThenApply$1(JerseyClientJettyModuleIT.java:103)
at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073)
at org.glassfish.jersey.client.JerseyInvocation$InvocationResponseCallback.completed(JerseyInvocation.java:1029)
at org.glassfish.jersey.client.ClientRuntime.processResponse(ClientRuntime.java:232)
at org.glassfish.jersey.client.ClientRuntime.access$200(ClientRuntime.java:62)
at org.glassfish.jersey.client.ClientRuntime$2.lambda$response$0(ClientRuntime.java:176)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:288)
at org.glassfish.jersey.client.ClientRuntime$2.response(ClientRuntime.java:176)
at org.glassfish.jersey.jetty.connector.JettyConnector$3.onComplete(JettyConnector.java:487)
at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:213)
at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:205)
at org.eclipse.jetty.client.HttpReceiver.terminateResponse(HttpReceiver.java:477)
at org.eclipse.jetty.client.HttpReceiver.terminateResponse(HttpReceiver.java:457)
at org.eclipse.jetty.client.HttpReceiver.responseSuccess(HttpReceiver.java:420)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.messageComplete(HttpReceiverOverHTTP.java:386)
at org.eclipse.jetty.http.HttpParser.handleContentMessage(HttpParser.java:587)
at org.eclipse.jetty.http.HttpParser.parseContent(HttpParser.java:1727)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:1556)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.parse(HttpReceiverOverHTTP.java:221)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.process(HttpReceiverOverHTTP.java:160)
at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.receive(HttpReceiverOverHTTP.java:91)
at org.eclipse.jetty.client.http.HttpChannelOverHTTP.receive(HttpChannelOverHTTP.java:91)
at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onFillable(HttpConnectionOverHTTP.java:194)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:936)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1080)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.util.concurrent.TimeoutException: Idle timeout 30000 ms
at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onIdleExpired(HttpConnectionOverHTTP.java:181)
at org.eclipse.jetty.io.AbstractEndPoint.onIdleExpired(AbstractEndPoint.java:407)
at org.eclipse.jetty.io.IdleTimeout.checkIdleTimeout(IdleTimeout.java:170)
at org.eclipse.jetty.io.IdleTimeout.idleCheck(IdleTimeout.java:112)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
... 1 more
```
Contributor guide
Research direction
Start with bootique-jersey-jakarta-client-jetty/src/test/java/io/bootique/jersey/client/jetty/JerseyClientJettyModuleIT.java at testGetRxThenApply, then inspect JettyConnector.apply around line 289 and the asynchronous response path shown in the stack trace. Reproduce the chained same-host calls and make the test complete without the 30-second idle timeout while preserving the working cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100