hypertrace / javaagent

Hypertrace OpenTelemetry Java agent with payload/body and headers data capture.
Apache License 2.0
33 stars 15 forks source link

Fix servlet exception accessing inputstream before the application #242

Closed pavolloffay closed 3 years ago

pavolloffay commented 3 years ago

This fixes accessing request inputstream/reader before the application for async requests. In other words the instrumentation could access input stream before the application - especially for async response.

This fixes the issue, however the instrumentation still tries to access the streams even though the application might not read the body at all. In the follow-up PR I will try to add a check to read the stream only if the app accessed it.

2021-01-25 05:35:34.391 [GraphQLServlet-4] INFO  g.k.s.HttpRequestHandlerImpl - Bad request: cannot create invocation input parser

java.lang.IllegalStateException: STREAMED

    at org.eclipse.jetty.server.Request.getReader(Request.java:1178) ~[jetty-server-9.4.30.v20200611.jar:9.4.30.v20200611]

    at graphql.kickstart.servlet.GraphQLPostInvocationInputParser.getGraphQLInvocationInput(GraphQLPostInvocationInputParser.java:33) ~[graphql-java-servlet-10.0.0.jar:?]

    at graphql.kickstart.servlet.HttpRequestHandlerImpl.handle(HttpRequestHandlerImpl.java:36) ~[graphql-java-servlet-10.0.0.jar:?]

    at graphql.kickstart.servlet.AbstractGraphQLHttpServlet.doRequest(AbstractGraphQLHttpServlet.java:148) ~[graphql-java-servlet-10.0.0.jar:?]

    at graphql.kickstart.servlet.AbstractGraphQLHttpServlet.lambda$doRequestAsync$2(AbstractGraphQLHttpServlet.java:136) ~[graphql-java-servlet-10.0.0.jar:?]

    at io.opentelemetry.javaagent.instrumentation.api.concurrent.RunnableWrapper.run(RunnableWrapper.java:28) [?:0.9.1]

    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:?]

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:?]

    at java.lang.Thread.run(Unknown Source) [?:?]

Signed-off-by: Pavol Loffay p.loffay@gmail.com