Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

POST request to grizzly-http-server times out #5812

Closed
divadpoc opened this issue Nov 29, 2024 · 9 comments
Closed

POST request to grizzly-http-server times out #5812

divadpoc opened this issue Nov 29, 2024 · 9 comments

Comments

@divadpoc
Copy link

divadpoc commented Nov 29, 2024

in the process of upgrading our code-base to Java21 (from Java17) I had to upgrade our Jersey version from 3.0.1. I started with the latest one, which currently is: 3.0.16 .

On the client side I'm using the Java-HTTP-client (inlcuded in Java itself). I'm using Temurin as JDK/JRE.

When the services finally started again, I encountered the time-out for POST requests. Therefore I created a simple Maven project that starts a grizzly-http server, and a corresponding client - see https://github.com/divadpoc/grizzly-test .

In the end, I started downgraded step by step until I met version 3.0.11, which works as expected..

Am I missing anything that's necessary to include in my project to get any later version running as well ?

Thanks and BR

Update w/ errors/trace

On the client side I get:

java.net.http.HttpTimeoutException: request timed out
    at java.net.http/jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:954)
    at java.net.http/jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:133)
    at com.test.client.Main.main(Main.java:36)

On the server side I get:

Unhandled exception occurred - null
java.io.EOFException
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.read(TCPNIOTransport.java:575)
    at org.glassfish.grizzly.nio.transport.TCPNIOTemporarySelectorReader.readNow0(TCPNIOTemporarySelectorReader.java:40)
    at org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorReader.read0(TemporarySelectorReader.java:152)
    at org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorReader.read0(TemporarySelectorReader.java:109)
    at org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorReader.read(TemporarySelectorReader.java:84)
    at org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorReader.read(TemporarySelectorReader.java:55)
    at org.glassfish.grizzly.AbstractReader.read(AbstractReader.java:43)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransportFilter.handleRead(TCPNIOTransportFilter.java:61)
    at org.glassfish.grizzly.filterchain.TransportFilter.handleRead(TransportFilter.java:133)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:88)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:246)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:178)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.read(DefaultFilterChain.java:309)
    at org.glassfish.grizzly.filterchain.FilterChainContext.read(FilterChainContext.java:662)
    at org.glassfish.grizzly.http.io.InputBuffer.blockingRead(InputBuffer.java:1037)
    at org.glassfish.grizzly.http.server.io.ServerInputBuffer.blockingRead(ServerInputBuffer.java:70)
    at org.glassfish.grizzly.http.io.InputBuffer.fill(InputBuffer.java:1060)
    at org.glassfish.grizzly.http.io.InputBuffer.read(InputBuffer.java:307)
    at org.glassfish.grizzly.http.server.NIOInputStreamImpl.read(NIOInputStreamImpl.java:60)
    at org.glassfish.jersey.message.internal.EntityInputStream.read(EntityInputStream.java:79)
    at org.glassfish.jersey.innate.io.InputStreamWrapper.read(InputStreamWrapper.java:54)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._loadMore(UTF8StreamJsonParser.java:220)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._skipWSOrEnd2(UTF8StreamJsonParser.java:3110)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._skipWSOrEnd(UTF8StreamJsonParser.java:3105)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:716)
    at com.fasterxml.jackson.databind.ObjectReader._verifyNoTrailingTokens(ObjectReader.java:2247)
    at com.fasterxml.jackson.databind.ObjectReader._bind(ObjectReader.java:2104)
    at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1249)
    at org.glassfish.jersey.jackson.internal.jackson.jaxrs.base.ProviderBase.readFrom(ProviderBase.java:829)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:234)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:213)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:133)
    at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundReadFrom(MappableExceptionWrapperInterceptor.java:49)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:133)
    at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1072)
    at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:657)
    at org.glassfish.jersey.server.ContainerRequest.readEntity(ContainerRequest.java:290)
    at org.glassfish.jersey.server.internal.inject.EntityParamValueParamProvider$EntityValueSupplier.apply(EntityParamValueParamProvider.java:73)
    at org.glassfish.jersey.server.internal.inject.EntityParamValueParamProvider$EntityValueSupplier.apply(EntityParamValueParamProvider.java:56)
    at org.glassfish.jersey.server.spi.internal.ParamValueFactoryWithSource.apply(ParamValueFactoryWithSource.java:50)
    at org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getParameterValues(ParameterValueHelper.java:68)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$AbstractMethodParamInvoker.getParamValues(JavaResourceMethodDispatcherProvider.java:109)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:176)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:93)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:478)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:400)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81)
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:256)
    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:265)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:235)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:684)
    at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:356)
    at org.glassfish.grizzly.http.server.HttpHandler$1.run(HttpHandler.java:190)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:535)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:515)
    at java.base/java.lang.Thread.run(Thread.java:1570)
@divadpoc
Copy link
Author

I just tried to use latest 3.1 version (3.1.9) and I'm experiencing the same problem. Doesn't work with latest 3.1, but when downgrading to 3.1.3 it's okay.

@divadpoc
Copy link
Author

divadpoc commented Dec 2, 2024

I just found out what I have to set on my HttpClient in order to have a successful response for my POST call:

explicitly setting the HTTP version 1.1 it works - the headers I get on the server side are:

Headers: {content-length=[79], host=[localhost:8080], user-agent=[Java-http-client/22], content-type=[application/json]}

when not explicitly setting the version, version 2 is used, and the following headers are sent (according to my DebugFilter)

Headers: {connection=[Upgrade, HTTP2-Settings], content-length=[79], host=[localhost:8080], http2-settings=[AAEAAEAAAAIAAAABAAMAAABkAAQBAAAAAAUAAEAA], upgrade=[h2c], user-agent=[Java-http-client/22], content-type=[application/json]}

My question now is: why do I need to explicitly set my HTTP version when using jersey grizzly http server with version 3.0.16, but it's working properly w/ version 3.0.11 ?

Thank you and BR, David

@jansupol
Copy link
Contributor

jansupol commented Dec 2, 2024

Interestingly enough, setting the version just to the module

        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>3.1.3</version>
        </dependency>

fixes the issue

@jansupol
Copy link
Contributor

jansupol commented Dec 3, 2024

These lines are responsible for the change. Note that the file is a repackaged Jackson file, not of Jersey origin.

READ_FULL_STREAM option has been added in Jackson 2.15, with a default value of TRUE. From the documentation:

Note that this means that behavior in earlier versions (2.14 and before) differs from 2.15 and later.

As a workaround, instead of .register(org.glassfish.jersey.jackson.JacksonFeature.class); you may use .register(new JacksonJaxbJsonProvider().disable(JaxRSFeature.READ_FULL_STREAM));

@divadpoc
Copy link
Author

divadpoc commented Dec 3, 2024

Thank you for your response and your findings.

I tried as you proposed, insteada of
.register(org.glassfish.jersey.jackson.JacksonFeature.class);

I register w/

                .register(
                        new JacksonJaxbJsonProvider()
                                .disable(JaxRSFeature.READ_FULL_STREAM)
                );

but I'm getting the following error:

java.lang.NoClassDefFoundError: com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector
	at org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JsonMapperConfigurator._resolveIntrospector(JsonMapperConfigurator.java:128)

which is true, as I do not depend on com.fasterxml.jackson.module:jackson-module-jaxb-annotations, but jackson-module-jakarta-xmlbind-annotations module instead, which is included via the jersey-media-json-jackson library, and, according to this should be the preferred way.

Is there any other way to disable the feature ?

@jansupol
Copy link
Contributor

jansupol commented Dec 3, 2024

Sorry about this. The fix for it is already in the development branch. For the time being, add

        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-jaxb-annotations</artifactId>
            <version>2.18.0</version>
        </dependency>

@divadpoc
Copy link
Author

divadpoc commented Dec 3, 2024

I was just about to say that I tried this. but now I get

java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
	at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.<init>(JaxbAnnotationIntrospector.java:137)

I think for now I just keep the setting at my http client to bind to HTTP version 1.1 .

when the next version is released, what changes would I have to make to disable the feature ?

@jansupol
Copy link
Contributor

I have put together #5816, which allows for better configuration of the JaxRSFeature for the Jersey Jackson module.

@jansupol
Copy link
Contributor

Closing as finished.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants