Repository navigation
fix(dedup): contaminate and latch asyncExecutors on background HTTP session-expiry listeners - #198
Merged
Merged
Conversation
…ession-expiry listeners
Background HTTP session-expiry timers (Tomcat StandardManager/ManagerBase,
Jetty HouseKeeper/SessionInactivityTimer, Undertow InMemorySessionManager)
can invoke application session listeners outside any HTTP request. Without
a hook, cleanup code executed during background session expiry can land
silently inside an unrelated later test's coverage window.
Hook container session-listener dispatch invokeinterface call sites across
Tomcat 8.5/9/10.1/11, Jetty 9.4/11/12.0/12.1 (including ee8/ee9 nested
SessionHandler, ee10/ee11 SessionHandler, and Jetty 12
core AbstractSessionManager/ManagedSession), and Undertow 2.2/2.3 for
HttpSessionListener, HttpSessionAttributeListener, HttpSessionBindingListener,
HttpSessionActivationListener, HttpSessionIdListener, and container-native
session listener interfaces:
- Keep Jetty 12 ee8/ee9 outer nested SessionHandler optional while requiring
its nested CoreSessionManager so Jetty 12.0.0/12.0.16/12.1.15 never log
false hook-failure warnings or falsely latch asyncExecutors=false.
- Fast-path as a no-op inside an active HTTP request or tracked/expired job
so synchronous HttpSession.invalidate() and changeSessionId() stay clean.
- Outside any tracked request or job, enter JobGate("session-listener") to
contaminate overlapping windows (session-listener:<class>#<method>) and
latch asyncExecutors=false.
- Skip exact container-internal bridges (SessionListenerBridge, Jetty 12
SessionHandler, Tomcat SingleSignOnListener) only on container-native
interfaces, and skip exact org.apache.tomcat.websocket.server.WsSessionListener
(auto-registered by Tomcat WsSci in Spring Boot and standalone Tomcat) only
on Servlet interfaces (never subclasses) so listener-free expiries stay clean.
- Document behavior and limits (e.g. Spring Session adapters) in README.md.
Signed-off-by: slayerjain <shubhamkjain@outlook.com>
Skip io.undertow.websockets.jsr.JsrWebSocketFilter$LogoutListener by exact class name on Servlet session-listener interfaces (matching Tomcat's WsSessionListener) so listener-free session expiries on Undertow deployments with WebSocket support (including Spring Boot's starter-undertow defaults) do not falsely contaminate overlapping windows or latch asyncExecutors=false. Subclasses remain tracked. Signed-off-by: slayerjain <shubhamkjain@outlook.com>
slayerjain
force-pushed
the
fix/session-expiry-listener-latch
branch
from
November 29, 2026 10:12
113eb2c to
f882094
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Background HTTP session-expiry timers (Tomcat
StandardManager/ManagerBase, JettyHouseKeeper/SessionInactivityTimer, UndertowInMemorySessionManager) can invoke application session listeners (HttpSessionListener,HttpSessionAttributeListener,HttpSessionBindingListener,HttpSessionActivationListener,HttpSessionIdListener, and container-native session listeners) outside any HTTP request. Without a session-listener hook, application cleanup code executed on session expiry can land silently inside an unrelated later test's coverage window.Changes
ServerEntries.java:org/apache/catalina/session/StandardSession(HttpSessionListener,HttpSessionAttributeListener,HttpSessionBindingListener,HttpSessionActivationListener,HttpSessionIdListener,org/apache/catalina/SessionListener).org/eclipse/jetty/server/session/SessionHandler,org/eclipse/jetty/server/session/Session,org/eclipse/jetty/ee8/nested/SessionHandler($CoreSessionManagerrequired; outer class optional),org/eclipse/jetty/ee9/nested/SessionHandler($CoreSessionManagerrequired; outer class optional),org/eclipse/jetty/ee10/servlet/SessionHandler,org/eclipse/jetty/ee11/servlet/SessionHandler,org/eclipse/jetty/session/AbstractSessionManager(Session$LifeCycleListener), andorg/eclipse/jetty/session/ManagedSession(Session$ValueListener:onSessionAttributeUpdate,onSessionActivation,onSessionPassivation).io/undertow/servlet/core/ApplicationListeners,io/undertow/servlet/core/SessionListenerBridge,io/undertow/servlet/handlers/SessionRestoringHandler, andio/undertow/server/session/SessionListeners.try/finallybridge callingRequestGate.enterSessionListener(listener, methodName, containerNative)andRequestGate.exitSessionListener(token)with fail-closed loader/callsite checks and idempotent load-time/retransform handling.RequestGate.java&JobGate.java:HttpSession.invalidate()andchangeSessionId()stay clean and never false-latch).JobGate.enter(label, "session-listener"): contaminates any overlapping test window withsession-listener:<listenerClass>#<methodName>AND latchesasyncExecutors=false.SessionListenerBridge, Jetty 12ee8/ee9nested &ee10/ee11SessionHandler, TomcatSingleSignOnListener) ONLY on container-native interfaces (containerNative=true), and skips exactorg.apache.tomcat.websocket.server.WsSessionListener(auto-registered by TomcatWsSciin Spring Boot and standalone Tomcat) ONLY on Servlet interfaces (containerNative=false, never subclasses), so listener-free session expiries stay clean.README.md:asyncExecutors=falselatching, in-request clean fast path, Tomcat defaultWsSessionListenerexemption, and limits (external session-store adapters such as Spring Session'sSessionEventHttpSessionListenerAdapter/HttpSessionAdapter, or containers loaded before the agent).SessionListenerHookTest.java,SessionExpiryApp.java,SessionExpiryTail.java):SessionListenerBridge&WsSessionListenerskips vs subclass fail-closed, ASM bytecode rewrite across all container dispatch classes (includingHttpSessionIdListener, multi-argonSessionAttributeUpdate, exception cleanup,containerNativebridge propagation, load-time idempotency, and Jetty 12ee8/ee9outer vs$CoreSessionManagerrequired semantics), and forked-JVM end-to-end tests on Tomcat 9, Jetty 9.4, and Undertow 2.2.Verification
clean verifyrelease profile +mvn -B -pl keploy-sdk -am test+./scripts/smoke-javaagent.sh+ no-cleanverifywithsha256sum -c): 451/451 PASS on JDK 21 (0 failures, 0 errors, 0 skipped).Failures > 0 && Errors == 0): 17/17 KILLED (0 survived, 0 compile errors, 0 runner errors).12.0.0,12.0.16,12.1.15(ee8/ee9nested$CoreSessionManager,bridges=10) + Tomcat10.1.34(StandardSession,bridges=11):verifyFail=0, 0 hook-failure warnings.ws=TruewithWsSessionListenerandHttpSessionIdListener), Spring Boot 3.3.5 default Tomcat, and Jetty 12ee9/ee10/ee11in bothKEPLOY_PROVENmodes: 144/144 rows PASS (0failures,0false marks/latches onws=True& Spring Boot default Tomcat).