Broadcasting to WS via threads results in occasional errror
Closed this issue · 1 comments
Get the following error when broadcasting via threads: "The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method." Imagine that multiple threads end up broadcasting to WS at same time, and the WS isn't done with a prior request.
Have mitigated by surrounding the broadcast code in an exclusive lock. However, occasionally, I get an "a timeout occurred after 30 seconds trying to acquire a exclusive lock with name" error.
See https://dev.lucee.org/t/websocket-issues-hanging-server/2386 for exact error mesage and trace.
You can reproduce the issue by something like the following, where Application.WebSocketsConnectionManager should exist as using the normal WebsocketRegister("/ws/{channel}", new BroadcastListener())
for (threadNum=1; threadNum<=100; threadNum++){
thread action='run' name='thread_#threadNum#' {
try{
sleep(500);
if (!isNull(Application.WebSocketsConnnectionManager)){
Application.WebSocketsConnnectionManager.broadcast("testChannel", "Test message");
}
}catch (any e){
writelog(file="websockets", text=serializeJson({"error":e}));
}
}
}
Fixed for 2.0.1 -- now all of the calls to sendXxx are synchronized