isapir/lucee-websocket

websocket.close fails when client's underlying session is removed from session storage

Opened this issue · 0 comments

dwkd commented

I am trying to have the server broadcast to a channel but before that, close all websockets of users who's web portal session has timed out.

I have the following steps:

  • Client logs in to application
  • a cf session is created in my session storage database cf_session_data
  • Client opens a WS to a registered Channel, handshake is successful
  • Server broadcasts a message
  • Client receives message successfully
  • I delete the session row from the cf_session_data (simulating a logout ... it's typical for lucee5 to remove the row on logout)
  • Server attempts to broadcast a new message, with the following steps:
    1. Looping through WebsocketsConnectionManager.getChannel( channelId).getSubscribers()
    2. Grabbing the web portal CFID from each subscriber's websocket.CFID (I create this property onOpen the first time they connect)
    3. Verify if cf_session_data contains any sessions with that CFID
    4. perform websocket.close()
    5. Server throws an uncatchable 500 error
    6. My workaround is to perform a websocket.unsubscribeAll() and after that a websocket.setMaxIdleTimeout(1). Both of these methods seem to still work, but it's a pretty janky workaround as it simply times out the socket. (On a sidenote here setMaxIdleTimeout is not implemented correctly. The argument should be milliseconds but they are actually seconds, as the 1 in this case is not immediate but actually takes 1 second to close the socket. I tried putting 5 and counted to 5 and lo and behold, again, behaves like seconds not milliseconds)