eclipse-ee4j / eclipse-ee4j/jersey

org.glassfish.jersey.client.InboundJaxrsResponse.readEntity() hangs in an async client

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

Description

A snippet of the client's stack looks like this:
```

at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:132)
at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1067)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:850)
at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:784)
at org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:297)
at org.glassfish.jersey.client.InboundJaxrsResponse$1.call(InboundJaxrsResponse.java:91)
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:365)
at org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:240)
at org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:88)
at com.hammerspace.jerseyusage.clientserver.Main$1.completed(Main.java:85)
at com.hammerspace.jerseyusage.clientserver.Main$1.completed(Main.java:78)

```

I have uploaded the reproducer at https://github.com/rumpelstiltzkin/jerseybug. In my experience, it always hangs with Jersey version 2.26 and more often than not with Jersey version 2.28. I have a separate commit to upgrade to 2.28, so you can remove/add just that commit to reproduce in both the versions.

In my debugging with version 2.26 I find that when the response payload is large (the value of content-length is large) then the first portion of the payload, including the header, is read in a 2K buffer defined by `HttpConnection.java::INPUT_BUFFER_SIZE` and then the client just hangs waiting for the subsequent payload because it knows, from the content-length, that there's more data expected. So in HttpParser.java::parse(ByteBuffer input) the value of `complete` is never set to true and so it never calls `httpResponse.getBodyStream().notifyAllDataRead()`. The consequence is that `AsynchronousBodyInputStream::read()`, after committing to a `SYNCHRONOUS` mode, hangs when it invokes `synchronousStream.read(...)`.

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.