Skip to content

JVM servlet containers and blocking frameworks (J2) ​

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.

J2 adds request boundaries to the classic, thread-per-request JVM servers: Apache Tomcat, Eclipse Jetty and Undertow, and therefore to everything that embeds them — Spring Boot (servlet stack), Spring MVC, Javalin, Spark, Dropwizard, Clojure Ring on Jetty, Micronaut and Quarkus on a servlet container, plain WAR deployments. It is part of the JVM agent: the same jar, the same compose-only change; there is nothing extra to install.

Covers ​

VersionsHook point
Apache Tomcat (standalone, embedded)8.5, 9, 10.1, 11Http11Processor.service (the connection) + CoyoteAdapter.service (each request)
Eclipse Jetty9.4, 10, 11HttpChannel.onRequest / handle / onCompleted
Eclipse Jetty12HttpChannelState.onRequest, HandlerInvoker.run, ChannelCallback completion
Undertow2.xConnectors.executeRootHandler (every handler run) + exchange completion
Spring Boot / Spring MVCBoot 2.x, 3.x (servlet stack)through Tomcat (default), Jetty or Undertow
Javalin4–6through Jetty
Spark Java2.xthrough Jetty 9.4
Dropwizard, Micronaut (servlet), Quarkus (servlet / quarkus-undertow), Ring + ring-jetty-adapter, WAR filesthrough the container they run on

Samples run for Tomcat 10.1, Spring Boot 3.4 (Tomcat), Jetty 11, Jetty 12, Javalin 6, Spark 2.9, Dropwizard 4, Clojure Ring 1.12 and Undertow 2.3 (see the table at the end). Micronaut's servlet runtime, quarkus-undertow and WAR deployments use the same container classes and have no sample of their own.

What the kernel links without the hook. These servers handle a request on one pool thread from start to finish, so the kernel's "one live client socket per thread" rule already links most of a request's syscalls. J2 adds what the kernel cannot know: where one request on a keep-alive connection ends and the next begins (request index), the response status, and — together with J1 — the request for work the handler hands to an executor, a CompletableFuture or a new thread.

Not covered here: Quarkus RESTEasy (classic and reactive) and Vert.x-based stacks run on Vert.x — see J3 (its Quarkus sample uses RESTEasy classic). Play's blocking actions run on Pekko / Akka HTTP or Play's Netty server, not on a servlet container — see J3.

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; J2 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"

For the official tomcat image (and anything started by catalina.sh), the same variable works: catalina.sh starts a JVM, which reads JAVA_TOOL_OPTIONS. CATALINA_OPTS / JAVA_OPTS are not needed.

The hub proposes it when it detects a JVM service (see J1); dependencies such as spring-boot-starter-web, org.apache.tomcat, org.eclipse.jetty, io.undertow, io.javalin, com.sparkjava, io.dropwizard rank it higher.

What it records ​

EventEmitted fromJoin key
request_beginTomcat: CoyoteAdapter.service entry, on the worker thread (the context is current there at once). Jetty 9.4–11: HttpChannel.onRequest (request head parsed); Jetty 12: HttpChannelState.onRequest; Undertow: the first Connectors.executeRootHandler for an exchangepeer address and port of the accepted socket, request index on that connection
context_enter / context_exitJetty / Undertow: every dispatch of the request to a thread (HttpChannel.handle, HandlerInvoker.run, executeRootHandler — also async re-dispatches and Undertow's exchange.dispatch() to a worker); Tomcat: async re-dispatch (CoyoteAdapter.asyncDispatch)context id
request_endTomcat: CoyoteAdapter.service returns (async requests: when Tomcat recycles the response); Jetty 9.4–11: HttpChannel.onCompleted; Jetty 12: the channel callback completes; Undertow: exchange completionstatus = the response status
spawned, connected, openedJ1's JDK hooks, with the request's contextchild pid, local port, pid + fd

The request index counts requests on the server's per-connection object: Tomcat's SocketWrapperBase, Jetty's EndPoint / Connection, Undertow's ServerConnection — each lives exactly as long as the TCP connection, so the index matches what the proxy counted on that connection.

Context following ​

The request's context is current on the thread that runs the servlet / handler. Everything that leaves that thread is followed by J1: executors, CompletableFuture, ForkJoinPool, new threads, virtual threads (Tomcat and Jetty with virtual-thread executors included: the request is current on the virtual thread and the agent reports each mount on a carrier). Servlet async (startAsync) is followed from dispatch to dispatch; work the application does on its own threads in between follows through J1's executor hooks.

Known gaps ​

  • HTTP/2 (h2c or TLS ALPN) is not covered yet: requests on HTTP/2 streams get no request_begin (no false links; the kernel rule still applies per thread).
  • Tomcat 8.0 and older, Jetty 9.3 and older: different internals, not hooked.
  • AJP connectors (Tomcat behind Apache httpd): not hooked.
  • Undertow's servlet layer on WildFly (JBoss Modules class loading) — the agent's classes are not visible to modules there, so WildFly is left alone.
  • Request index on Jetty 12 counts per Connection object; HTTP/1.1 upgrades (WebSocket) end the request at the 101 response.

Safety ​

J2's hooks are a handful of method entries/exits in the containers' request path; each handler reads a few values (addresses, status) by reflection and catches everything, so a container 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. J2 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 org/apache/catalina/connector/CoyoteAdapter (or org/eclipse/jetty/server/HttpChannel, io/undertow/server/Connectors) when the container's classes load.
  • Which links did a flow get? The hub shows each link's method; this package's are hook:J2.
  • Requests but no request indexes beyond 0: the client (or the proxy in front) does not reuse connections — expected.
  • No events for a WAR in a standalone Tomcat: check that JAVA_TOOL_OPTIONS reaches the JVM (setenv.sh scripts that reset the environment); the Picked up JAVA_TOOL_OPTIONS line must appear in catalina.out.

Samples ​

SampleServerEvents checked
tomcatembedded Tomcat 10.1, plain servletkeep-alive indexes, status, spawn, file, connect, executor hand-off
spring-bootSpring Boot 3.4 web MVC on Tomcatsame
jettyembedded Jetty 11, servletsame
jetty12embedded Jetty 12, core handlersame
javalinJavalin 6 (Jetty 11)same
sparkSpark 2.9 (Jetty 9.4)same
dropwizardDropwizard 4 (Jersey on Jetty)same
ringClojure 1.12, Ring with ring-jetty-adapter 1.12 (Jetty 11)same
undertowUndertow 2.3, handler dispatched to a workersame (context switches not compared: the I/O thread's exit and the worker's enter race)

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