Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-3915

Automatic session timeout causes exceptions with websockets enabled

XMLWordPrintable

    • None

      Steps to Reproduce

      run any zul file, e.g. /test.zul

      <zk>
      	<label value="Session: ${session.nativeSession.id}, Desktop: ${desktop.id}"></label>
      </zk>
      

      And enable automatic timeout handling
      (with a short timeout for faster debugging and referring to itself to create a loop also for better debugging)

      <session-config>
      	<device-type>ajax</device-type>
      	<timeout-uri>/test.zul</timeout-uri>
      	<automatic-timeout>true</automatic-timeout>
      	<session-timeout>10</session-timeout>
      </session-config>
      

      Current Result

      *1) *Jetty reliably shows the following exception when session timeout occurs:

      Mar 29, 2018 4:15:15 PM org.zkoss.zkmax.au.websocket.WebSocketEndPoint onError
      WARNING: SERVER ERROR
      java.util.concurrent.TimeoutException: Idle timeout expired: 10000/10000 ms
      	at org.eclipse.jetty.io.IdleTimeout.checkIdleTimeout(IdleTimeout.java:166)
      	at org.eclipse.jetty.io.IdleTimeout$1.run(IdleTimeout.java:50)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
      	at java.util.concurrent.FutureTask.run(FutureTask.java)
      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      	at java.lang.Thread.run(Thread.java:748)
      

      *2) *Tomcat rarely shows a NPE:

      Mar 29, 2018 4:00:15 PM org.zkoss.zkmax.au.websocket.WebSocketEndPoint onError
      WARNING: SERVER ERROR
      org.zkoss.zk.ui.UiException: java.lang.NullPointerException
      	at org.zkoss.zkmax.au.websocket.WebSocketEndPoint$1.onMessage(WebSocketEndPoint.java:107)
      	at org.zkoss.zkmax.au.websocket.WebSocketEndPoint$1.onMessage(WebSocketEndPoint.java:102)
      	at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:394)
      	at org.apache.tomcat.websocket.server.WsFrameServer.sendMessageText(WsFrameServer.java:119)
      	at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:495)
      	at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:294)
      	at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:133)
      	at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:82)
      	at org.apache.tomcat.websocket.server.WsFrameServer.doOnDataAvailable(WsFrameServer.java:171)
      	at org.apache.tomcat.websocket.server.WsFrameServer.notifyDataAvailable(WsFrameServer.java:151)
      	at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:148)
      	at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:54)
      	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53)
      	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
      	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
      	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      	at java.lang.Thread.run(Thread.java:748)
      Caused by: java.lang.NullPointerException
      	at org.zkoss.zk.ui.http.ZKWebSocket.getDesktop(ZKWebSocket.java:68)
      	at org.zkoss.zkmax.au.websocket.WebSocketEndPoint.process(WebSocketEndPoint.java:153)
      	at org.zkoss.zkmax.au.websocket.WebSocketEndPoint.access$000(WebSocketEndPoint.java:62)
      	at org.zkoss.zkmax.au.websocket.WebSocketEndPoint$1.onMessage(WebSocketEndPoint.java:105)
      	... 19 more
      

      3) Another reported NPE is the following:

      java.lang.NullPointerException
       at org.zkoss.zkmax.au.websocket.WebSocketFilter.doFilter(WebSocketFilter.java:40)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:615)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
       at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
       at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
       at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
       at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1770)
       at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1729)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
       at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
       at java.lang.Thread.run(Thread.java:748)
      

      Expected Result

      No or Meaningful exceptions in the logs.

      Debug Info

      In case 3) further debugging showed that the call below returned NULL resulting in the NPE

      org.zkoss.zkmax.au.websocket.WebSocketFilter : Line 40

      httpSession.getAttribute(org.zkoss.zk.ui.sys.Attributes.ZK_SESSION)
      

      Root Cause

      Missing Null Handling

      Workaround

      not necessary, currently only affects timed out sessions

            wenninghsu wenninghsu
            cor3000 cor3000
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: