Skip to content

fix(vertx-web): finish vertx.route-handler via RoutingContext.addEndHandler fallback#11312

Draft
zarirhamza wants to merge 1 commit intomasterfrom
zarir/sles-2837-vertx-web-finish-route-handler
Draft

fix(vertx-web): finish vertx.route-handler via RoutingContext.addEndHandler fallback#11312
zarirhamza wants to merge 1 commit intomasterfrom
zarir/sles-2837-vertx-web-finish-route-handler

Conversation

@zarirhamza
Copy link
Copy Markdown
Contributor

Summary

In synthetic Vert.x transports — most importantly quarkus-amazon-lambda-rest's VirtualClientConnection (the in-memory Netty channel that AWS Lambda HTTP runtimes use) — Http1xServerResponse.end() synchronously closes the underlying connection, so by the time the inlined if (!closed && endHandler != null) guard runs, closed is true and the registered endHandler is silently skipped.

RouteHandlerWrapper.handle() relies on response().endHandler(...) to finish the vertx.route-handler span. When that hook never fires, the span is started but never finished, never enqueued on the writer, and silently dropped. Every child span parented to it (jakarta-rs.request, netty.client.request, downstream aws.http/aws.apigateway inferred spans) ends up orphaned in the trace UI.

Fix

Also register a finish via RoutingContext.addEndHandler(...), which fires on routing-context completion regardless of underlying connection state and on both success and failure. Both paths funnel through a shared idempotent RouteHandlerWrapper.finishHandlerSpan(routingContext) so the second one to fire on real-network transports is a no-op.

Files touched:

  • RouteHandlerWrapper.java (+23/-0): register the fallback in the span-starter branch; add finishHandlerSpan static helper.
  • EndHandlerWrapper.java (-9/+1): delegate to the shared helper instead of duplicating the finish logic.

Test plan

  • Existing vertx-web-4.0 unit/integration tests still pass.
  • Add a synthetic test that uses a stubbed HttpServerResponse whose end() skips the user-registered endHandler (mimicking the closed-connection path) and asserts the route-handler span is still finished via addEndHandler.
  • Verified end-to-end on Quarkus 3.15.4 / Java 21 Lambda chain (caller -> netty.client.request -> callee) with Datadog Lambda Extension v96. Pre-fix: 5/5 invocations Started, 0/5 Finished. Post-fix: 5/5 Started, 5/5 Finished, single connected trace tree at the backend.

Refs

SLES-2837

…andler fallback

Vert.x's `Http1xServerResponse.end(Buffer, PromiseInternal)` invokes
the registered `endHandler` only when `closed == false` at the moment
the response body has been written. In synthetic transports such as
quarkus-amazon-lambda-rest's `VirtualClientConnection` (in-memory
Netty channel) the writes and the connection close happen
synchronously inside `responseComplete()`, so by the time the
`!closed` guard runs `closed` is already `true` and `endHandler` is
silently skipped.

Symptom: `RouteHandlerWrapper` starts a `vertx.route-handler` span
for every route in the chain (e.g. Quarkus's AuthenticationHandler)
but `EndHandlerWrapper.handle` is never called, so the span is never
finished. The span dies in PendingTrace and is not enqueued on the
writer. All children parented to that span (`jakarta-rs.request`,
`netty.client.request`, downstream `aws.http`/`aws.apigateway`
inferred spans) end up orphaned in the trace UI.

Fix: also register a finish via `RoutingContext.addEndHandler`, which
fires on routing-context completion regardless of underlying
connection state and on both success and failure. Both paths funnel
through a shared idempotent `finishHandlerSpan` so the second one to
fire on real-network transports is a no-op.

Verified end-to-end against a Quarkus 3.15.4 / Java 21 Lambda chain
(caller -> netty.client.request -> callee) on Datadog Lambda
Extension v96. Pre-fix: 5/5 invocations Started, 0/5 Finished.
Post-fix: 5/5 Started, 5/5 Finished, single connected trace tree
in the UI.

Refs: SLES-2837
@zarirhamza zarirhamza requested a review from a team as a code owner May 7, 2026 20:04
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Hi! 👋 Thanks for your pull request! 🎉

To help us review it, please make sure to:

  • Add at least one type, and one component or instrumentation label to the pull request

If you need help, please check our contributing guidelines.

@zarirhamza zarirhamza marked this pull request as draft May 7, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant