Fix ApacheHttpAsync race condition
MODIFY
dd-java-agent/instrumentation/apache-httpasyncclient-4/src/test/groovy/ApacheHttpAsyncClientNullCallbackTest.groovy
dd-java-agent/instrumentation/apache-httpasyncclient-4/src/test/groovy/ApacheHttpAsyncClientNullCallbackTest.groovy
import datadog.trace.agent.test.base.HttpClientTest
import datadog.trace.instrumentation.apachehttpasyncclient.ApacheHttpAsyncClientDecorator
-import io.opentracing.util.GlobalTracer
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.nio.client.HttpAsyncClients
import org.apache.http.message.BasicHeader
@@ -34,10 +33,7 @@ class ApacheHttpAsyncClientNullCallbackTest extends HttpClientTest<ApacheHttpAsy
Future future = client.execute(request, null)
future.get()
if (callback != null) {
- // Request span is closed asynchronously even in regards to returned future so we have to wait here.
- if (GlobalTracer.get().activeSpan() != null) {
blockUntilChildSpansFinished(1)
- }
callback()
}
return 200

MODIFY
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/AgentTestRunner.java
dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/AgentTestRunner.java
@@ -200,6 +200,10 @@ public abstract class AgentTestRunner extends Specification {
public void blockUntilChildSpansFinished(final int numberOfSpans) throws InterruptedException {
final DDSpan span = (DDSpan) io.opentracing.util.GlobalTracer.get().activeSpan();
+ if (span == null) {
+ // If there is no active span avoid getting an NPE
+ return;
+ }
final PendingTrace pendingTrace = span.context().getTrace();
while (pendingTrace.size() < numberOfSpans) {

Fix ApacheHttpAsync race condition