Skip to content

JVM Netty and reactive stacks (J3) ​

Ready

This package comes with the J1 hook: when the hub proposes J1 for a container, this is part of it, and nothing changes until a player approves the proposal (Hook proposals). The cheat sheet has the steps by hand.

J3 is for JVM services whose requests do not own a thread: Netty servers and everything built on Netty — Spring WebFlux (Reactor Netty), Vert.x and Quarkus, Micronaut, Ktor's Netty engine, Spring Cloud Gateway — Ktor's pure-Kotlin CIO engine, Akka HTTP / Pekko HTTP, and Helidon 4, which serves each connection on a virtual thread. In these servers one event-loop thread runs many requests interleaved, so the kernel cannot link anything to a request; J3 reports which request is running on which thread, and the JVM agent then links the spawns, connects and file opens. It is part of the JVM agent: the same jar and the same compose-only change.

Covers ​

VersionsHook point
Netty4.1HttpObjectDecoder.decode (requests), AbstractChannelHandlerContext.invokeChannelRead (handlers), HttpObjectEncoder.encode (responses), event-loop tasks
Spring WebFlux / Reactor NettyBoot 2.x, 3.xthrough Netty
Vert.x3.9, 4.x (vertx-core, vertx-web)through Netty (Vert.x's own request decoder extends Netty's)
Quarkus (RESTEasy Reactive and classic, Reactive Routes)2.x, 3.xthrough Vert.x / Netty
Micronaut (Netty runtime)3.x, 4.xthrough Netty
Ktor, Netty engine2.x, 3.xthrough Netty, coroutines through J4
Ktor, CIO engine2.x, 3.xServerRequestScope creation (request start, tied to the request coroutine), CIOApplicationResponse.setStatus, the request coroutine's completion (end); coroutines through J4
Spring Cloud Gateway, plain Netty serversthrough Netty
Helidon WebServer ("Níma")4.xHttp1Connection.route (one request on the connection's virtual thread)
Pekko HTTP1.0, 1.1, 1.2 (Scala 2.12 / 2.13 / 3)Tcp.IncomingConnection creation (local address), the connection's TcpStreamLogic in the same stream interpreter (peer, connection), ParserOutput.RequestStart created by the request parser (requests), GraphInterpreter.processPush of the request's HttpRequest into the handler flow (context), ResponseRenderingContext created by ControllerStage (responses)
Akka HTTP10.2 on Akka 2.6 (later versions have the same engine, not verified)same hooks, package akka.
Play Framework, Akka HTTP / Pekko HTTP server backendthrough Akka HTTP / Pekko HTTP (not sampled)

Samples run for plain Netty 4.1, Spring WebFlux (Boot 3.4), Vert.x 4.5, Quarkus 3.17 (RESTEasy classic), Micronaut 4.7, Ktor 3 on CIO, Helidon 4.1, Pekko HTTP 1.1, Akka HTTP 10.2, and Ktor 3 on Netty (that sample lives in J4).

What the kernel links without the hook. Nothing, in the common case: an event loop serves all connections from one or a few threads, and Helidon's virtual threads move between carrier threads. J3 is needed for any request-level link.

How it gets in ​

From a registry (local development, or a build with network; the same release as the hook directory): Maven Central garden.ctf.vulnboxd:vbxtrace-agent:1.0.0: mvn dependency:unpack -Dartifact=garden.ctf.vulnboxd:vbxtrace-agent:1.0.0:zip:dist -DoutputDirectory=target/agent, then -javaagent:target/agent/vbxtrace/jvm/vbxtrace-agent.jar; see Local development.

The JVM agent's compose-only change; J3 needs nothing else:

diff
 services:
   <service>:
+    volumes:
+      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
+    environment:
+      JAVA_TOOL_OPTIONS: "-javaagent:/opt/vbxtrace/jvm/vbxtrace-agent.jar"

Quarkus fast-jar (java -jar quarkus-run.jar) and Micronaut/Ktor fat jars pick the variable up like any JVM. Native images (GraalVM native-image, Quarkus/Micronaut native builds) are not JVMs and ignore JAVA_TOOL_OPTIONS; see the gaps.

The hub proposes it when it detects a JVM service (see J1); dependencies such as io.netty, io.vertx, io.quarkus, io.micronaut, io.ktor, spring-boot-starter-webflux, io.helidon rank it higher.

What it records ​

EventEmitted fromJoin key
request_beginNetty: a server-side HTTP decoder produced an HttpRequest (on the event loop). Ktor CIO: the request's ServerRequestScope is created (in the request coroutine). Helidon: Http1Connection.route entry (on the connection's virtual thread). Pekko/Akka HTTP: the request parser produced a request start (on the connection's stream actor)peer address and port of the Netty Channel / CIO connection / Helidon connection / accepted Pekko-Akka TCP connection (its Tcp.IncomingConnection), request index on it
context_enter / context_exitNetty: around every pipeline handler call for one of the request's messages (the HttpRequest and its HttpContent parts), around event-loop tasks submitted while the request was current. Helidon: J1's virtual-thread mount / unmount. Pekko/Akka HTTP: around every handler-flow stage call for the request's HttpRequest (the bind's watchTermination, the mapAsync running the route or handler function); futures and actor messages from there on via J1context id
request_endNetty: the encoder writes the response's LastHttpContent (or a FullHttpResponse); the oldest open request of that channel ends (pipelined requests end in order) with the HttpResponse's status. Ktor CIO: the request coroutine completes (after the response channel closed), with the status the call set. Helidon: route returns, with the response's status. Pekko/Akka HTTP: the server's controller stage hands a final response to the renderer (1xx except 101 skipped); the oldest open request of the connection ends, in pipelining order, with that response's statusstatus
spawned, connected, openedJ1's JDK hooks, with the request's contextchild pid, local port, pid + fd

The request index is counted per Netty Channel (one per accepted TCP connection), per CIO connection (its address objects, which live as long as the connection) or per Helidon Http1Connection.

Context following ​

  • On the event loop: the request is current while a pipeline handler processes one of its messages, including everything that handler calls synchronously (Reactor operators subscribed in that call, Vert.x route handlers, Micronaut controllers that run on the event loop).
  • Event-loop tasks: a task submitted to a Netty event loop (execute, schedule) while a request is current carries it to where the task runs.
  • Worker pools: WebFlux publishOn(Schedulers.boundedElastic()), Vert.x executeBlocking and worker verticles, Quarkus' blocking endpoints (jboss-threads), Micronaut @ExecuteOn, Ktor/coroutine dispatchers: followed by J1's executor hooks (JDK ThreadPoolExecutor/ScheduledThreadPoolExecutor/ ForkJoinPool, EnhancedQueueExecutor) and J4 for coroutines.
  • Callbacks triggered by other I/O (a reactive chain resumed by a database driver's response on another channel): the request is not current there unless the work went through one of the mechanisms above — such work is left unlinked rather than guessed.
  • Pekko / Akka HTTP: the request is current while a stage of the handler flow processes its HttpRequest, including the route or handler function called synchronously there. Scala Futures, CompletionStages on Pekko/Akka dispatchers and actor messages are followed by J1's ForkJoin hooks.
  • Event-loop threads never inherit a request from the code that started them.

Known gaps ​

  • HTTP/2 and HTTP/3 on Netty (Http2FrameCodec, Http2MultiplexHandler) and gRPC-Java: not covered.
  • Reactive continuations resumed by unrelated I/O (see above), and Reactor's own Schedulers.parallel() when it is not backed by a JDK executor: unlinked.
  • Pekko/Akka HTTP: HTTP/2 (enable-http2, h2c and ALPN) is not covered; HTTP/1.1 connections on an HTTP/2-enabled binding are, through the same engine (not sampled). Servers on other transports (Unix domain sockets, a custom serverLayer joined to something other than Pekko's Tcp), or graphs that fuse several accepted connections into one stream, get no events. With a streamed response entity the request ends when the response head is handed to the renderer, before the body has been sent. Work the handler hands to a user-materialized stream with its own .async boundary is followed only through dispatchers. A request whose connection fails before any response is rendered gets no request_end. Akka 2.7+ / Akka HTTP 10.4+ (BSL licensed) were not checked.
  • Quarkus fast-jar (quarkus-run.jar, the default packaging): Quarkus' class loader opens the application's jars again for classes first used by the first request(s), so those requests show some opened events for jar files. Real facts; uber-jars (the sample) do not have them.
  • GraalVM native images: no JVM, no agent. A native Quarkus/Micronaut/Spring binary needs a source change (not offered yet).
  • Netty's native transports (epoll, io_uring) open client connections in native code: outgoing connections made by Netty clients (WebClient, Vert.x clients) get no connected event; the sensor still sees the connect syscall, but cannot attribute it on an event loop.
  • WebSocket upgrades end the HTTP request at the 101 response; frames on the socket afterwards are not a request.

Safety ​

J3's hooks sit on Netty's per-message paths (decoder, encoder, handler invocation, event-loop tasks). Each checks a lock-free "anything to do?" flag first and returns at once while no request context exists — always the case without a tracer. Handlers read addresses and statuses by reflection and catch everything; a Netty version whose internals differ simply gets no events. Everything in J1's safety section applies.

Sample results: every sample's recorded events match its golden event file, and its responses are byte-identical with the hook failing on every call (chaos) and without the hook (baseline). Overhead has not been measured yet.

Turning it off ​

Set VBXTRACE=0 in the service's environment and restart it, or revert the change that added the hook; vulnboxd's rollback covers a hook that breaks a service. J3 cannot be switched off separately from the agent.

Troubleshooting ​

  • Are the probes there? readelf -n /usr/local/lib/vulnboxd/trace/libvbxtrace-x86_64.so lists them; sudo bpftrace -l 'usdt:/usr/local/lib/vulnboxd/trace/libvbxtrace-x86_64.so:*' too.
  • Is the hook loaded? See J1. With VBXTRACE_DEBUG=1 the agent prints instrumented io/netty/handler/codec/http/HttpObjectDecoder (and the encoder, the handler context and the event-loop classes) when Netty loads.
  • Which links did a flow get? The hub shows each link's method; this package's are hook:J3.
  • Requests appear but their spawns/connects are not linked: the work ran on a thread the request did not follow to (see "Context following"); moving it to a JDK executor or a coroutine dispatcher makes it follow.
  • A native image: file <binary> shows an ELF executable instead of a java command; the agent cannot apply.

Samples ​

SampleServerEvents checked
nettyNetty 4.1, HttpServerCodec + HttpObjectAggregator, handler on the event loopkeep-alive indexes, status, spawn, file, connect, executor hand-off
webfluxSpring Boot 3.4 WebFluxsame
vertxVert.x 4.5 web routersame
quarkusQuarkus 3.17, RESTEasy classic (Vert.x in front, resources on the jboss-threads worker pool), uber-jarsame (context switches not compared: the event loop's exit and the worker's enter race)
micronautMicronaut 4.7 on Netty, controller on the event loopsame
ktor-cioKtor 3 on the CIO engine, coroutines hopping to Dispatchers.IO / Defaultkeep-alive indexes, status, spawn, file, connect, withContext / async file writes linked to their request (context switches not compared)
helidonHelidon 4.1 WebServersame (virtual-thread mount/unmount events not compared: their number depends on timing)
pekko-httpPekko HTTP 1.1 (pekko-stream 1.1), Java routing DSL, default settings (no remote-address setting)keep-alive indexes, status, spawn, file, connect, executor hand-off; context switches compared (the bind's watchTermination and the route's mapAsync)
akka-httpAkka HTTP 10.2 on Akka 2.6, Java routing DSLsame

Run them with hooks/run-samples.sh jvm --package j3.