From 78299192294359c4250aac8560f2510bf0d0a8b1 Mon Sep 17 00:00:00 2001 From: Joe Rayhawk Date: Mon, 7 Nov 2022 18:13:33 -0800 Subject: Signal websocket I/O fiber to terminate on connection close. Previously I/O fibers would overstay their welcome and start interfering with eachother for new connections. --- src/obswebsocket.cr | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/obswebsocket.cr b/src/obswebsocket.cr index 968957f..66a19f3 100644 --- a/src/obswebsocket.cr +++ b/src/obswebsocket.cr @@ -140,6 +140,8 @@ module OBSWebSocket end obs_pubsub.send( msg[1] ) end + elsif msgtuple[1] == "break" + break elsif msgtuple[1] == "subscribe events" reschan = msgtuple[0] if reschan @@ -270,8 +272,6 @@ module OBSWebSocket end end obs_pubsub.run - sleep 10 - next rescue ex : Socket::ConnectError | IO::Error if @connecterror < 3 print ex.message @@ -279,16 +279,15 @@ module OBSWebSocket ( @connecterror == 3 ) && ( @connecterror += 1 ) && print ". Suppressing further repeat errors." print "\n" end - obs_pubsub && obs_pubsub.close - @negotiated = false - sleep 10 - next rescue ex pp ex pp ex.backtrace? + ensure obs_pubsub && obs_pubsub.close @negotiated = false - next + @@reqchan.send( { nil, "break" } ) # ask reader fiber to terminate + # Should we invalidate all the cached ORM data here? + sleep 10 end end end -- cgit v1.2.3