fukamachi / websocket-driver

WebSocket server/client implementation for Common Lisp
BSD 2-Clause "Simplified" License
104 stars 28 forks source link

Define conditions for threads to die on their own #63

Closed nyx-land closed 1 year ago

nyx-land commented 2 years ago

This is my (admittedly naive) fix to #49, which as far as I can tell was being caused by calling BT:DESTROY-THREAD when a thread is in a potentially blocking state (waiting for input on the socket). In my experience with other libraries that depend on the client package this bug can make it essentially unusable.

This just changes the loop to check if the connection is in a :CLOSED state, and if not, only reads if (LISTEN (SOCKET CLIENT)) returns true (so that it doesn't block). I had to add a sleep condition for each iteration so it doesn't spin out and exhaust the stack. Since the code already stores information about the state of the connection, it made sense to make use of that to let the threads die with some dignity.

whitehackrpg commented 1 year ago

Just to confirm: I ended up here when trying to stop lispcord from running sbcl at 100% cpu, and the fix works.

fukamachi commented 1 year ago

Sorry for the delay. Thanks for your efforts!