Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,19 @@ public static void stopSpan(

final AgentSpan span = spanFromContext(scope.context());

if (request.isAsyncStarted()) {
if (DECORATE.safeIsAsyncStarted(request)) {
AtomicBoolean activated = new AtomicBoolean();
FinishAsyncDispatchListener asyncListener =
new FinishAsyncDispatchListener(scope, activated, !isDispatch);
// Jetty doesn't always call the listener, if the request ends before
request.setAttribute(DD_FIN_DISP_LIST_SPAN_ATTRIBUTE, asyncListener);
try {
request.getAsyncContext().addListener(asyncListener);
} catch (final IllegalStateException e) {
} catch (final IllegalStateException | AbstractMethodError ignored) {
// org.eclipse.jetty.server.Request may throw an exception here if request became
// finished after check above. We just ignore that exception and move on.
}
if (!request.isAsyncStarted() && activated.compareAndSet(false, true)) {
if (!DECORATE.safeIsAsyncStarted(request) && activated.compareAndSet(false, true)) {
if (!isDispatch) {
DECORATE.onResponse(span, resp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
import datadog.trace.bootstrap.instrumentation.decorator.HttpServerDecorator;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
Expand Down Expand Up @@ -127,4 +128,19 @@ public AgentSpan onError(final AgentSpan span, final Throwable throwable) {
}
return span;
}

/**
* Safely calls ServletRequest#isAsyncStarted. Some 2.x wrappers might be dangling in the 3.x
* classpath and produce an AbstractMethodError
*
* @param servletRequest the servlet request.
* @return the real call result or false when the method does not exist in the provided object.
*/
public boolean safeIsAsyncStarted(final ServletRequest servletRequest) {
try {
return servletRequest.isAsyncStarted();
} catch (AbstractMethodError ignored) {
return false;
}
}
}
Loading