-
Notifications
You must be signed in to change notification settings - Fork 828
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
Change Async Servlet span end logic to fix race condition on Undertow #2992
Changes from 11 commits
a2dc390
3f57b9a
0af651b
308ff19
26ce952
a0377ee
4fafd7f
b2552fa
287b0f2
995eba1
512dc97
763aef7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.servlet.v3_0; | ||
|
||
import static io.opentelemetry.instrumentation.servlet.v3_0.Servlet3HttpServerTracer.tracer; | ||
|
||
import io.opentelemetry.javaagent.instrumentation.api.CallDepthThreadLocalMap; | ||
import javax.servlet.AsyncContext; | ||
import javax.servlet.http.HttpServletRequest; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.implementation.bytecode.assign.Assigner; | ||
|
||
public class Servlet3AsyncStartAdvice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void startAsyncEnter() { | ||
// This allows to detect the outermost invocation of startAsync in method exit | ||
trask marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CallDepthThreadLocalMap.incrementCallDepth(AsyncContext.class); | ||
} | ||
|
||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void startAsyncExit( | ||
@Advice.This(typing = Assigner.Typing.DYNAMIC) HttpServletRequest request) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that instead of dynamic typing to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
int callDepth = CallDepthThreadLocalMap.decrementCallDepth(AsyncContext.class); | ||
|
||
if (callDepth != 0) { | ||
// This is not the outermost invocation, ignore. | ||
return; | ||
} | ||
|
||
if (request != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can request really be null here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced with |
||
if (!tracer().isAsyncListenerAttached(request)) { | ||
tracer().attachAsyncListener(request); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to add calls to
setAsyncListenerResponse
in each app server instrumentation, or can we do it once in servlet instrumentation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, since it is possible for requests to be handled entirely within app server handlers without servlet advices ever triggering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can those requests have servlet async listeners?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jetty handlers and Tomcat valves both expose the
ServletRequest
and are allowed to generate the response without a servlet ever being invoked. I have not tested usingstartAsync
in them, but the documentation does not say that either of them would only support synchronous responses.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add comments to the code explaining this? otherwise worried these lines could be removed thinking they aren't really needed, and I don't think we have any tests that it would break
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added those comments for all the appservers.