Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-20778

ServletRequestListener events should be guarded by GlobalRequestControllerHandler

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 37.0.0.Final
    • 36.0.1.Final
    • Web (Undertow)
    • None

      Currently, web requests are guarded from server shutdown by a RequestController ControlPoint that is installed as an "outer" handler wrapper. This ensures that the beginning and ending of the handler chain are guarde with ControlPoint.beginRequest()/requestComplete().
      However, this wrapping excludes the ServletInitialHandler, which is the head of the chain, and is responsible for dispatching the request to the handler chain. Since the ServletInitialHandler.handleRequest(...) implementation invokes ServletRequestListener.requestInitialized(...) events before delegating to the main handler chain, the events are not guarded from server shutdown.
      This stack trace illustrates an exception that should have been prevented by the RequestController:

      2025-07-09 00:08:24,575 ERROR [io.undertow.servlet.request] (default task-43) UT015005: Error invoking method requestInitialized on listener class org.jboss.weld.module.web.servlet.WeldInitialListener: java.lang.IllegalStateException: WFLYCLWEBUT0003: Session manager was stopped
      	at org.wildfly.clustering.web.undertow@8.1.0.GA-redhat-00009//org.wildfly.clustering.web.undertow.session.DistributableSessionManager.getSessionCloseTask(DistributableSessionManager.java:103)
      	at org.wildfly.clustering.web.undertow@8.1.0.GA-redhat-00009//org.wildfly.clustering.web.undertow.session.DistributableSessionManager.getSession(DistributableSessionManager.java:201)
      	at io.undertow.servlet@2.3.18.SP1-redhat-00001//io.undertow.servlet.spec.ServletContextImpl.getSession(ServletContextImpl.java:884)
      	at io.undertow.servlet@2.3.18.SP1-redhat-00001//io.undertow.servlet.spec.HttpServletRequestImpl.getSession(HttpServletRequestImpl.java:454)
      	at org.jboss.weld.core@5.1.5.Final-redhat-00001//org.jboss.weld.module.web.servlet.SessionHolder.requestInitialized(SessionHolder.java:47)
      	at org.jboss.weld.core@5.1.5.Final-redhat-00001//org.jboss.weld.module.web.servlet.HttpContextLifecycle.requestInitialized(HttpContextLifecycle.java:266)
      	at org.jboss.weld.core@5.1.5.Final-redhat-00001//org.jboss.weld.module.web.servlet.WeldInitialListener.requestInitialized(WeldInitialListener.java:151)
      	at io.undertow.servlet@2.3.18.SP1-redhat-00001//io.undertow.servlet.core.ApplicationListeners.requestInitialized(ApplicationListeners.java:263)
      	at io.undertow.servlet@2.3.18.SP1-redhat-00001//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:275)
      	at io.undertow.servlet@2.3.18.SP1-redhat-00001//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
      	at io.undertow.servlet@2.3.18.SP1-redhat-00001//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:132)
      	at io.undertow.servlet@2.3.18.SP1-redhat-00001//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
      	at io.undertow.servlet@2.3.18.SP1-redhat-00001//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
      	at org.wildfly.extension.undertow@8.1.0.GA-redhat-00009//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1421)
      	at org.wildfly.extension.undertow@8.1.0.GA-redhat-00009//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1421)
      	at org.wildfly.extension.undertow@8.1.0.GA-redhat-00009//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1421)
      	at org.wildfly.extension.undertow@8.1.0.GA-redhat-00009//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1421)
      	at io.undertow.servlet@2.3.18.SP1-redhat-00001//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:256)
      	at io.undertow.servlet@2.3.18.SP1-redhat-00001//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:101)
      	at io.undertow.core@2.3.18.SP1-redhat-00001//io.undertow.server.Connectors.executeRootHandler(Connectors.java:395)
      	at io.undertow.core@2.3.18.SP1-redhat-00001//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:896)
      	at org.jboss.threads@2.4.0.Final-redhat-00001//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
      	at org.jboss.threads@2.4.0.Final-redhat-00001//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
      	at org.jboss.threads@2.4.0.Final-redhat-00001//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
      	at org.jboss.threads@2.4.0.Final-redhat-00001//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
      	at org.jboss.xnio@3.8.16.Final-redhat-00001//org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
      	at java.base/java.lang.Thread.run(Thread.java:840)
      

      Because the request listeners are not guarded, the session manager, required by the WeldInitialListener, was allowed to stop, causing the above exception.
      Although not demonstrated here, ServletRequestListener.requestDestroyed(...) events have the same problem.

      To fix this, the GlobalRequestControllerHandler should be installed as an "initial" handler wrapper, where ControlPoint.requestComplete() is triggered by an HttpServerExchange completion handler.

              pferraro@redhat.com Paul Ferraro
              pferraro@redhat.com Paul Ferraro
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: