snowdrop-zen / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
1 stars 0 forks source link

Response head already sent Exception #402

Closed snowdrop-bot closed 3 years ago

snowdrop-bot commented 3 years ago

Describe the bug

When using lazy JWT authentication with http permissions observing below exceptions if JWT token in the request is expired.

[io.ver.ext.web.RoutingContext] (vert.x-eventloop-thread-22) Unhandled exception in router: java.lang.IllegalStateException: Response head already sent
or
[io.ver.ext.web.RoutingContext] (vert.x-eventloop-thread-0) Unhandled exception in router: java.lang.IllegalStateException: Response has already been written

Quarkus Extensions used: cdi, security, smallrye-context-propagation, smallrye-jwt, smallrye-openapi, swagger-ui, vertx, vertx-web

Config used:

quarkus.http.auth.proactive=false
quarkus.http.auth.permission.permit.paths=/q/*,/api/hello
quarkus.http.auth.permission.permit.policy=permit
quarkus.http.auth.permission.loggedin.paths=/api/*
quarkus.http.auth.permission.loggedin.policy=authenticated

Expected behavior

No Runtime exceptions

Actual behavior

Observing below exception

2021-08-24 17:00:00,950 ERROR [io.ver.ext.web.RoutingContext] (vert.x-eventloop-thread-22) Unhandled exception in router: java.lang.IllegalStateException: Response head already sent
    at io.vertx.core.http.impl.Http1xServerResponse.checkHeadWritten(Http1xServerResponse.java:675)
    at io.vertx.core.http.impl.Http1xServerResponse.setStatusCode(Http1xServerResponse.java:144)
    at io.quarkus.vertx.http.runtime.QuarkusErrorHandler.handle(QuarkusErrorHandler.java:77)
    at io.quarkus.vertx.http.runtime.QuarkusErrorHandler.handle(QuarkusErrorHandler.java:24)
    at io.vertx.ext.web.impl.RouteState.handleFailure(RouteState.java:1133)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:148)
    at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:133)
    at io.vertx.ext.web.impl.RoutingContextImpl.doFail(RoutingContextImpl.java:591)
    at io.vertx.ext.web.impl.RoutingContextImpl.fail(RoutingContextImpl.java:184)
    at io.vertx.ext.web.impl.RoutingContextImpl.fail(RoutingContextImpl.java:173)
    at io.quarkus.vertx.http.runtime.security.HttpAuthorizer$3.accept(HttpAuthorizer.java:140)
    at io.quarkus.vertx.http.runtime.security.HttpAuthorizer$3.accept(HttpAuthorizer.java:137)

Observed below exception as well though not able to reproduce it always

2021-08-24 14:02:19,090 ERROR [io.ver.ext.web.RoutingContext] (vert.x-eventloop-thread-0) Unhandled exception in router: java.lang.IllegalStateException: Response has already been written
    at io.vertx.core.http.impl.Http1xServerResponse.checkValid(Http1xServerResponse.java:669)
    at io.vertx.core.http.impl.Http1xServerResponse.endHandler(Http1xServerResponse.java:310)
    at io.vertx.ext.web.impl.RoutingContextImpl.getEndHandlers(RoutingContextImpl.java:573)
    at io.vertx.ext.web.impl.RoutingContextImpl.addEndHandler(RoutingContextImpl.java:436)
    at io.quarkus.vertx.web.runtime.RouteHandler.handle(RouteHandler.java:90)
    at io.quarkus.vertx.web.runtime.RouteHandler.handle(RouteHandler.java:22)
    at io.vertx.ext.web.impl.RouteState.handleFailure(RouteState.java:1133)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:148)
    at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:133)
    at io.vertx.ext.web.impl.RoutingContextImpl.doFail(RoutingContextImpl.java:591)
    at io.vertx.ext.web.impl.RoutingContextImpl.fail(RoutingContextImpl.java:184)
    at io.vertx.ext.web.impl.RoutingContextImpl.fail(RoutingContextImpl.java:173)
    at io.quarkus.vertx.http.runtime.security.HttpAuthorizer$3.accept(HttpAuthorizer.java:140)
    at io.quarkus.vertx.http.runtime.security.HttpAuthorizer$3.accept(HttpAuthorizer.java:137)

How to Reproduce?

https://github.com/MM87037/routing-error

Start the service and run below command

curl "http://localhost:8080/api/user" -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJUZXN0Iiwic3ViIjoidW5tVW93TlBRNVEzdVh4WDNPRVkwTnRTRnNOWFZ6SlZnYVZyNm40MWNYbyIsInByZWZlcnJlZF91c2VybmFtZSI6IlRlc3RVc2VyQGNvbXBhbnkuY29tIiwiYXVkIjoiZjkzZWUxYTgtYmExYS00NDk0LWJmZTEtNjQzODIzMDIyNWVhIiwiaWF0IjoxNjI5NzMzMzE1LCJleHAiOjE2Mjk3MzY5MTUsIm5hbWUiOiJUZXN0IFVzZXIiLCJyb2xlcyI6WyJ3cml0ZSIsInJlYWQiLCJyZWxlYXNlIl0sImp0aSI6ImUzMGMxNWZjLTA0YzEtNDM0Yi1iZTZjLTU0N2E3Zjk4MjI0MiJ9.f52Q1JrH4JjeDbwn4NthuBYursCjeRrgd4uvCx0wGpilxaOVm7nvHlFkTKbiRofpEl8kE4YEangEGpiXPfn33Q5fZ_C2TjgQyrbNu9-IbSeDStLxIbhawW-NjyTI3EQY0zUrN9aOHvOWDitNTUVjBxHCIf1WTmyL15X6XT1qBczpTZKr-kkFs2L0Gxereu_gNxWgUPcyfC0vTOhjt3prZcpksv2W26gpKdTdJBmXm0xeOlkdxeIao_2kiJWTxJ22aUSLCESodNex-QV-40EjUz7B4YHSfEJ16mUjgLAOcpIwjjjZAvdHV92oa6alIgbbb35VjeqlPmKc29gQJNQP1Q'

or Run maven build

mvn clean verify

Output of uname -a or ver

Windows 10 Git Bash or Linux ids-slpdf-service-117-qd7hx 3.10.0-1160.36.2.el7.x86_64 #1 SMP Thu Jul 8 02:53:40 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.12" 2021-07-20

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.0 and above

Build tool (ie. output of mvnw --version or gradlew --version)

maven 3.8.1

Additional information

No response


https://github.com/quarkusio/quarkus/issues/19621


$upstream:19621$