From 68399596d0153f7ec1909aa818236b963e898310 Mon Sep 17 00:00:00 2001 From: "He-Pin(kerr)" Date: Fri, 27 Nov 2026 03:47:35 +0800 Subject: [PATCH] test: cover concurrent HTTP/2 request isolation after a route failure Motivation: The existing HTTP/2 failure test checks a subsequent request, not a request already in flight when an application route fails. Modification: Wait for two ordinary requests to reach the same route over one HTTP/2 connection. Verify that a failed application future produces a correlated 500, then complete the healthy request and verify its correlated 200 and full body. Result: The test guards per-request failure isolation without changing production behavior. References: RFC 9113 Section 5; RFC 9110 Section 15.6.1. --- .../engine/http2/Http2ClientServerSpec.scala | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ClientServerSpec.scala b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ClientServerSpec.scala index 6ee016d36..aa7c2a5a5 100644 --- a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ClientServerSpec.scala +++ b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/Http2ClientServerSpec.scala @@ -39,6 +39,7 @@ import pekko.http.scaladsl.model.{ Uri } import pekko.http.scaladsl.model.headers.HttpEncodings +import pekko.http.scaladsl.server.{ Directives, Route } import pekko.http.scaladsl.settings.ClientConnectionSettings import pekko.http.scaladsl.settings.ServerSettings import pekko.http.scaladsl.unmarshalling.Unmarshal @@ -303,6 +304,44 @@ class Http2ClientServerSpec extends PekkoSpecWithMaterializer( expectClientResponse().status should be(StatusCodes.OK) } + "complete a concurrent request when another route fails" in new TestSetup { + override def handler: HttpRequest => Future[HttpResponse] = { + import Directives._ + val applicationHandler = super.handler + Route.toFunction(extractRequest(request => complete(applicationHandler(request)))) + } + + def sendAndObserve(path: String): ServerRequest = { + sendClientRequest(HttpRequest(uri = path).addAttribute(requestIdAttr, RequestId(path))) + val observed = expectServerRequest() + observed.request.uri.path.toString shouldBe path + observed + } + + try { + val failing = sendAndObserve("/failing") + val healthy = sendAndObserve("/healthy") + + // Both requests reached the application before either response was released. + EventFilter[TE](occurrences = 1).intercept { + failing.promise.failure(TE("application failure")) + val response = expectClientResponse() + response.attribute(requestIdAttr) shouldBe Some(RequestId("/failing")) + response.status shouldBe StatusCodes.InternalServerError + response.discardEntityBytes().future.futureValue + } + + healthy.sendResponse(HttpResponse(entity = "healthy response")) + val response = expectClientResponse() + response.attribute(requestIdAttr) shouldBe Some(RequestId("/healthy")) + response.status shouldBe StatusCodes.OK + Unmarshal(response.entity).to[String].futureValue shouldBe "healthy response" + } finally { + try clientRequestsOut.sendComplete() + finally binding.terminate(1.second).futureValue(timeout(3.seconds)) + } + } + "return internal server error when handler throws synchronously" in new TestSetup { override def handler: HttpRequest => Future[HttpResponse] = _ => throw TE("boom-sync")