lucee / extension-websocket

GNU Lesser General Public License v2.1
0 stars 0 forks source link

Error thrown when client times out #4

Closed webonix closed 3 months ago

webonix commented 5 months ago

After connecting to Lucee WebSocket, then not doing anything for a while it seems like the session times out, and that causes Lucee to throw an error

from logs

"Severity","ThreadID","Date","Time","Application","Message"
"INFO","http-nio-8888-exec-6","03/30/2024","07:29:22","demo","host=127.0.0.1 port=8091"
"ERROR","Thread-100","03/30/2024","07:30:25","endpoint-factory",
"The WebSocket session [0] has been closed and no method (apart from close()) may be called on a closed session;java.lang.IllegalStateException: 
The WebSocket session [0] has been closed and no method (apart from close()) may be called on a closed session
    at org.apache.tomcat.websocket.WsSession.checkState(WsSession.java:806)
    at org.apache.tomcat.websocket.WsSession.getQueryString(WsSession.java:721)
    at org.lucee.extension.websocket.util.WSUtil.getQueryString(WSUtil.java:500)
    at org.lucee.extension.websocket.util.WSUtil.createPageContext(WSUtil.java:338)
    at org.lucee.extension.websocket.util.AsyncInvoker.run(AsyncInvoker.java:31)
"
michaeloffner commented 4 months ago

if the session timeouts, there is nothing the server thread can do to reconnect, because the connection get initialized by the client. only solution to this is see, is the possibility to set a custom idle or live timeout.

webonix commented 4 months ago

I resolved be having the client sending a heartbeat every 15 seconds

michaeloffner commented 4 months ago

"problem" here is the idle timeout, i added support to set a custom idle timeout in 2 ways

  1. set in the component itself as following: property name="idleTimeout" type="numeric" default=600;
  2. set in config file with "idleTimeout=300" 1 overrules 2

commit: https://github.com/lucee/extension-websocket/commit/aa24b26fce7d3ed67f3564ce45d06b889be3d7ce

webonix commented 4 months ago

@michaeloffner nice :-)

what are all the option for the config file now?

michaeloffner commented 3 months ago

{ "directory": "{lucee-config}/websockets/", "requestTimeout": 50, "idleTimeout": 300 }

directory = location of the components requestTimeout = timeout in seconds for a single request of a client idleTimeout = how long in seconds does a session idle before it get closed

BTW you can simply delete the json file and restart Lucee, then the extension will create the file new with al the option with the default values.

webonix commented 3 months ago

nice one, @michaeloffner Thank you