Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Request has already been read (Vertx) #16571

Closed
gwenneg opened this issue Apr 16, 2021 · 13 comments
Closed

Request has already been read (Vertx) #16571

gwenneg opened this issue Apr 16, 2021 · 13 comments
Labels
area/vertx kind/bug Something isn't working triage/out-of-date This issue/PR is no longer valid or relevant

Comments

@gwenneg
Copy link
Member

gwenneg commented Apr 16, 2021

Describe the bug

I updated Quarkus from 1.9.0 to 1.13.x in a project recently and ran into the following exception:

java.lang.IllegalStateException: Request has already been read
	at io.vertx.core.http.impl.HttpServerRequestImpl.checkEnded(HttpServerRequestImpl.java:596)
	at io.vertx.core.http.impl.HttpServerRequestImpl.handler(HttpServerRequestImpl.java:306)
	at io.quarkus.vertx.http.runtime.ResumingRequestWrapper.handler(ResumingRequestWrapper.java:18)
	at io.vertx.ext.web.impl.HttpServerRequestWrapper.handler(HttpServerRequestWrapper.java:82)
	at io.vertx.ext.web.handler.impl.BodyHandlerImpl.handle(BodyHandlerImpl.java:86)
	at io.vertx.ext.web.handler.impl.BodyHandlerImpl.handle(BodyHandlerImpl.java:42)
	at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
	at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:137)
	at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
	at io.quarkus.vertx.http.runtime.VertxHttpRecorder$4.handle(VertxHttpRecorder.java:338)
	at io.quarkus.vertx.http.runtime.VertxHttpRecorder$4.handle(VertxHttpRecorder.java:316)
	at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
	at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:137)
	at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
	at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup$3.handle(VertxHttpHotReplacementSetup.java:86)
	at io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup$3.handle(VertxHttpHotReplacementSetup.java:75)
	at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:327)
	at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:366)
	at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:834)

It is thrown randomly if a BodyHandler is appended to a route and that route is then called from an HTTP request:

    @PostConstruct
    public void init(@Observes Router router) {
        router.route().handler(BodyHandler.create());
        router.get("/test").handler(this::doSomething);
    }

Expected behavior

No exception thrown.

Actual behavior

HTTP request is served sometimes, and sometimes it fails because of the exception.

To Reproduce

https://github.com/gwenneg/quarkus-request-already-read

Steps to reproduce the behavior:

  1. ./mvnw clean quarkus:dev
  2. Open http://localhost:8080/test in a browser and refresh the page until it fails.

Environment (please complete the following information):

Output of java -version

openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9.1+1)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9.1+1, mixed mode)

Quarkus version or git rev

1.13.2.Final

@gwenneg gwenneg added the kind/bug Something isn't working label Apr 16, 2021
@gwenneg
Copy link
Member Author

gwenneg commented Apr 16, 2021

BodyHandlerBean may play a role in this but I'm really not sure.

@gwenneg
Copy link
Member Author

gwenneg commented Apr 16, 2021

cc @cescoffier @stuartwdouglas

@gwenneg
Copy link
Member Author

gwenneg commented Apr 16, 2021

It seems the exception is only thrown for requests which are not supposed to have a body (GET for example). On the other hand, a request with a body (like POST) seems to always be served correctly.

@gwenneg
Copy link
Member Author

gwenneg commented Apr 16, 2021

Workaround: append a BodyHandler only to routes that actually need to access the request body.

@stuartwdouglas
Copy link
Member

I think this may already be fixed by #16460

@stuartwdouglas
Copy link
Member

Actually probably not, if this still happens in 1.13.2

@cescoffier
Copy link
Member

@geoand fixed an issue related to that recently.

@geoand
Copy link
Contributor

geoand commented Jun 6, 2021

Indeed, @gwenneg can you retest?

@gwenneg
Copy link
Member Author

gwenneg commented Jun 6, 2021

Is your fix included in 1.13.6 @geoand?

@geoand
Copy link
Contributor

geoand commented Jun 6, 2021

I don't think we backported it

@gsmet
Copy link
Member

gsmet commented Jun 6, 2021

Which one is it? I will probably prepare a new 1.13 this week.

@geoand
Copy link
Contributor

geoand commented Jun 6, 2021

#17551

I just added the backport label

@cescoffier
Copy link
Member

Closing - looks outdated. Please reopen if the problem remains.

@cescoffier cescoffier added the triage/out-of-date This issue/PR is no longer valid or relevant label Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/vertx kind/bug Something isn't working triage/out-of-date This issue/PR is no longer valid or relevant
Projects
None yet
Development

No branches or pull requests

5 participants