Skip to content

feat(dedup): enable safe dedup on Jetty 11/12 and Undertow 2.2/2.3 - #197

Open
slayerjain wants to merge 5 commits into
mainfrom
feat/jetty-undertow-safe-dedup
Open

slayerjain wants to merge 5 commits into
mainfrom
feat/jetty-undertow-safe-dedup

Conversation

@slayerjain

@slayerjain slayerjain commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Enables safe per-test dedup (asyncExecutors=true, windowCut=true, failing closed on untracked async hand-offs) for Jetty 11 / 12 / 12.1 and Undertow 2.2 / 2.3 (including minimal Spring Boot Jetty and Undertow apps), without allowlisting any user-callback-capable pool or executor (EnhancedQueueExecutor, JBossThread, ManagedThreadPoolExecutor, XnioWorker$DefaultThreadPoolExecutor), and closes server-owned executor, scheduler, and abstract timer escape paths across Jetty 9.4/11/12/12.1 and Undertow 2.2/2.3 using exact, cited (callerClass#callerMethod) allowlists with zero package-prefix wildcards.

Root Causes Fixed

  1. Jetty 11 / 12 / 12.1 startup latch: Load-time constant-pool scan previously hit relocated/new Jetty 10/11/12 classes (AdaptiveExecutionStrategy, server.internal.HttpConnection + $HttpStreamOverHTTP1, SslConnection$SslEndPoint + $IncompleteWriteCallback, ShutdownService, SerializedInvoker$Link) and rarely-used helpers (Graceful.shutdown, VirtualThreads.executeOnVirtualThread, ThreadPool.executeImmediately, Invocable$InvocationType$1.runWithoutBlocking).
  2. Undertow 2.2 / 2.3 lazy worker spawn: XnioWorker / EnhancedQueueExecutor lazily spawns XNIO-1 task-* threads on the first HTTP request (TaskPool / EnhancedQueueExecutor -> JBossThread.start()), which previously tripped JdkSinkBridge.onThreadStart() unless recognized via the exact io.undertow.server.Connectors#executeRootHandler stack-frame check.
  3. Server-owned executor, scheduler, and timer escape paths: App or library code holding a Jetty QueuedThreadPool, ReservedThreadExecutor, Scheduler, TimerScheduler, ContextHandler$ScopedContext, Server$ServerContext, VirtualThreads.execute, CyclicTimeout, CyclicTimeouts, IdleTimeout, SocketChannelEndPoint (even when handed a real ServerConnector ManagedSelector with a null or foreign SelectionKey), ByteArrayEndPoint, or Undertow XnioWorker/XnioIoThread/WorkerUtils could bypass call-site rewriting via reflection or unrewritten third-party libraries.
  4. Servlet AsyncContext.dispatch() (Spring MVC Callable / DeferredResult) on Jetty 9.4/11/12.0/12.1: Preserves asyncExecutors=true and zero contamination for legitimate servlet async dispatches via exact HttpChannelState#scheduleDispatch (9.4/11) and ee10/ee11 ServletChannelState#scheduleDispatch (12.0/12.1) caller + task checks, while keeping all public Jetty forwarders fail-closed for app, library, and reflective callers.

Changes

  • SinkAllowlist.java:
    • Replaces package-prefix trust with exact, cited (callerClass#callerMethod) allowlists for every server sink (QueuedThreadPool, ReservedThreadExecutor, ScheduledExecutorScheduler, TimerScheduler, IdleTimeout, CyclicTimeout, CyclicTimeouts, XnioWorker, WorkerThread).
    • Transparently skips only exact thin server delegates (EatWhatYouKill, AdaptiveExecutionStrategy, and exact "execute" methods on SelectorManager, HttpChannel, ee10/ee11 ServletChannel, ContextHandler$ScopedContext, Server$ServerContext, VirtualThreads for Jetty pools; WorkerUtils, ParseTimeoutUpdater, ConnectionUtils for WorkerThread) while keeping TimerScheduler#run and WorkerThread#run visible so self-re-arms resolve cleanly.
    • Enforces receiver/task ownership guards:
      • isServerConnectorOwnedEndPoint: verifies SocketChannelEndPoint (and SslConnection's underlying network endpoint) belongs to an exact ServerConnector$ServerConnectorManager ManagedSelector AND that _key is a SelectionKey whose channel() == _channel and selector() == ManagedSelector._selector.
      • HttpChannelState#scheduleDispatch (Jetty 9.4/11) permits only exact HttpChannel/HttpChannelOverHttp tasks; ee10/ee11 ServletChannelState#scheduleDispatch (Jetty 12.0/12.1) verifies ContextHandler$ScopedContext$$Lambda + inner ServletChannel capture as an additional guard alongside the exact caller frame.
      • TimerScheduler#run permits only task == receiver of exact TimerScheduler.
      • WorkerThread#run permits only ParseTimeoutUpdater.
  • ServerEntries.java & JdkSinkBridge.java:
    • Instruments all Jetty & Undertow server executor, scheduler, and abstract timer entry points, plus exact ThreadPool.executeImmediately and ScheduledExecutorScheduler.schedule(Runnable, Duration).
  • Tests (keploy-sdk/pom.xml, ForkedAsyncAndHonestyTest.java, JdkSinkBridgeTest.java):
    • Stages Jetty 11.0.24, Jetty 12.0.16 (ee10), Jetty 12.1.15 (ee11, copy-jetty121 + jakarta.servlet-api 6.1.0), and Undertow 2.3.18 in the JDK 17+ profile and runs full forked-JVM clean-dedup, AsyncContext.start, AsyncContext.dispatch (Callable / DeferredResult), and adversarial escape rows on all four servers in both prefix and index modes.
    • Adds JdkSinkBridgeTest rows proving app-built SocketChannelEndPoint handed a started ServerConnector's real ManagedSelector with null or foreign SelectionKey fails closed, and proving a live transformed TimerScheduler self-re-arm keeps asyncExecutors=true.

Safe Fail-Closed Scope Notes

  • On Jetty 12, servlet ReadListener/WriteListener wakeups and DelayedHandler/EagerContentHandler/QoSHandler re-dispatches reach a skipped forwarder from an unlisted frame and fail closed (asyncExecutors=false); on Jetty 9.4/11, HttpChannelOverHTTP2 async dispatches also fail closed safely.
  • Background HTTP session-expiry listeners (HttpSessionListener.sessionDestroyed, etc.) are not part of this PR and are tracked in a dedicated follow-up PR.

Verification

  • Full Maven test suite + release-profile Javadoc + scripts/smoke-javaagent.sh: 453/453 PASS on JDK 21 (and full JDK 8/11/17/21 matrix in CI).
  • Compile-checked mutation suite (explicit mvn test-compile / package -DskipTests check before test execution): 8/8 KILLED (N2, N3, N4, N7, N10, MF1, M15, M16, compile_errors=[], survived=[]).

Keep asyncExecutors=true and clean per-window dedup on Jetty 11/12/12.1
and Undertow 2.2/2.3 (including Spring Boot Jetty and Undertow starters)
without allowlisting any user-callback-capable pool or executor:

- Hook org.xnio.XnioWorker.execute(Runnable) via RequestGate.handXnioWorker
  and enterXnioWorkerDispatch/exitXnioWorkerDispatch (paired with
  UNARMED_REQUEST_DEPTH for pre-connect server requests) so XNIO worker
  dispatch tracks tasks and lazily spawned XNIO-1 worker threads safely
  while failing closed on outside-window XnioWorker.execute, unreadable
  classloaders, or user-created EnhancedQueueExecutor/JBossThread pools.
- Exempt only hooked, non-overriding XnioWorker instances (verifying both
  execute(Runnable) on XnioWorker and all submit overloads on
  AbstractExecutorService) from RequestGate's untracked-executor check.
- Classify Jetty 11/12 internal I/O/strategy/shutdown classes (relocated
  HttpConnection, SslEndPoint, AdaptiveExecutionStrategy, ShutdownService,
  SerializedInvoker$Link) in the load-time scan allowlist, and hook
  user-callable or rarely-used helpers (Graceful.shutdown,
  VirtualThreads.executeOnVirtualThread, ThreadPool.executeImmediately,
  Invocable$InvocationType$1.runWithoutBlocking, Undertow's
  ServerWebSocketContainer, and Spring's DefaultPartHttpMessageReader)
  with fail-closed latch-on-call instrumentation.
- Add only Spring Boot 3.x/4.x zero-callback infra thread callers
  (BackgroundPreinitializer and Jetty GracefulShutdown) to SinkAllowlist.
- Remove Undertow 2.2 waivers in ForkedAsyncAndHonestyTest and add
  isolated JDK 17+ forked integration rows for Jetty 11.0.24, Jetty 12.0.16
  (ee10), and Undertow 2.3.18 across prefix and index modes plus escape tests.

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
Rewrite app calls to XnioIoThread.executeAfter and executeAtInterval to
emit untracked-async flags so delayed I/O selector tasks never escape a
dedup window silently.

Hook server-owned executor and scheduler sinks (Jetty QueuedThreadPool,
MonitoredQueuedThreadPool, ExecutorThreadPool, ReservedThreadExecutor,
TryExecutor$NoTryExecutor, ScheduledExecutorScheduler, TimerScheduler;
Undertow PipeliningExecutor and XNIO WorkerThread) with an exact-class
caller check that allows only the server's own internal packages and
fails closed (contaminating the active window and latching
asyncExecutors=false) on app, third-party library, or reflective
hand-offs across Jetty 9.4/11/12/12.1 and Undertow 2.2/2.3.

Add unit and forked tests covering XnioWorker override verification,
tag-7 latch-on-call fallback, per-entry allowlist citations and
behaviour rows, retransform idempotency, and reflective/library escapes.

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
… server executor and timer sinks

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
…AsyncContext.dispatch

- Verify Jetty IdleTimeout receivers via SinkAllowlist.isServerConnectorOwnedEndPoint so app-built SocketChannelEndPoint and SslConnection wrappers fail closed unless owned by a ServerConnector ManagedSelector and its channel SelectionKey.
- Preserve Servlet AsyncContext.dispatch() (Spring MVC Callable / DeferredResult) across Jetty 9.4, 11, 12.0 (ee10), and 12.1 (ee11) via exact HttpChannelState#scheduleDispatch (HttpChannel/HttpChannelOverHttp task check) and ServletChannelState#scheduleDispatch (ScopedContext -> ServletChannel lambda check), while keeping public forwarders fail-closed for direct, library, and reflective callers.
- Keep TimerScheduler#run visible and restricted to self-rearm (task == receiver, exact TimerScheduler), remove dead/non-direct caller entries, and add unit + forked regressions across Jetty 9.4/11/12.0/12.1 and Undertow 2.2/2.3.

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
… and TimerScheduler rows

Pre-merge test coverage and allowlist cleanup:
- Add copy-jetty121 artifact set (Jetty 12.1.15 ee11-servlet/server/http/io/util/session/security + jakarta.servlet-api 6.1.0) in the JDK 17+ profile and run the JakartaJetty12App forked suite on ee11 (AsyncContext.dispatch Callable/DeferredResult + all escape probes).
- Add JdkSinkBridgeTest rows proving app-built SocketChannelEndPoint handed a started ServerConnector's real ManagedSelector with null or foreign SelectionKey fails closed, and proving a live transformed TimerScheduler self-re-arm keeps asyncExecutors=true.
- Remove unused QueuedThreadPool$2#run allowlist entry from SinkAllowlist.

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
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