diff --git a/dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy b/dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy index 9c2aa5988ea..1e1af1a211c 100644 --- a/dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy +++ b/dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy @@ -1234,7 +1234,6 @@ abstract class HttpServerTest extends WithHttpServer { } } - @Flaky(value = "https://github.com/DataDog/dd-trace-java/issues/9396", suites = ["PekkoHttpServerInstrumentationAsyncHttp2Test"]) def "test exception"() { setup: def method = "GET" diff --git a/dd-java-agent/instrumentation/pekko/pekko-http-1.0/src/baseTest/scala/PekkoHttpTestWebServer.scala b/dd-java-agent/instrumentation/pekko/pekko-http-1.0/src/baseTest/scala/PekkoHttpTestWebServer.scala index 54a4983daff..01fca998cd7 100644 --- a/dd-java-agent/instrumentation/pekko/pekko-http-1.0/src/baseTest/scala/PekkoHttpTestWebServer.scala +++ b/dd-java-agent/instrumentation/pekko/pekko-http-1.0/src/baseTest/scala/PekkoHttpTestWebServer.scala @@ -275,6 +275,13 @@ object PekkoHttpTestWebServer { ): HttpRequest => Future[HttpResponse] = { request => Future { syncHandler(request) + }.recover { case e: Exception => + // Recover from exceptions to return a proper HTTP response instead of a + // failed Future. When the Future fails, the span completion depends on + // async continuation cleanup which can race with the test's trace assertion, + // causing flaky timeouts waiting for the trace to be written. + HttpResponse(status = EXCEPTION.getStatus, entity = e.getMessage) + .withDefaultHeaders(defaultHeader) } }