allinurl / gwsocket

fast, standalone, language-agnostic WebSocket server RFC6455 compliant
http://gwsocket.io
MIT License
750 stars 67 forks source link

When disconnecting from fifo CPU usage goes very high #53

Closed tomski-spqr closed 4 weeks ago

tomski-spqr commented 2 months ago
  1. Started gwsocket with: ./gwsocket --pipein=in.fifo --pipeout=out.fifo

  2. Open a console and do: cat out.fifo

  3. Connect with the test html application to the websocket and send an "Hello world" message. --> The message is printed on the console as expected.

  4. Break (CTRL-C) the cat command.

As soon as I stop the cat command (and thus disconnect from the pipe), the CPU usage of gwsocket jumps to almost 100%

allinurl commented 2 months ago

Thanks for the heads-up. It seems like it might be related to the select() call. Could you please run it with strace and let me know which call is consuming all the CPU?

tomski-spqr commented 2 months ago

On holiday for a while, hence the delay :-)

poll([{fd=3, events=POLLIN}, {fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=7, events=POLLIN}, {fd=8, events=0}], 5, -1) = 1 ([{fd=8, revents=POLLERR}])

Seems fd=8 (I guess this the file descriptor from out.fifo) causes a POLLERR

Probably the FIFO must be closed and re-opened when the reader (cat in this case) disconnects. I will check again after my holiday.

tomski-spqr commented 2 months ago

Fixed with attached patch. 2024-08-11-fix-high-cpu.patch.gz

allinurl commented 4 weeks ago

I completely overlooked this update. Thanks for submitting the patch! I’ve pushed it upstream, and it will be included in the next release.