summaryrefslogtreecommitdiff
path: root/src/obswebsocket.cr
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@fairlystable.org>2022-11-07 18:13:33 -0800
committerJoe Rayhawk <jrayhawk@fairlystable.org>2022-11-07 18:18:52 -0800
commit78299192294359c4250aac8560f2510bf0d0a8b1 (patch)
tree52d773244afecc1f2b6f98ee43b5d0ce5fa5cf80 /src/obswebsocket.cr
parent9f8002b5b553a69e36ae506af4805b877939575e (diff)
downloadcrystal-obs-websocket-78299192294359c4250aac8560f2510bf0d0a8b1.tar.gz
crystal-obs-websocket-78299192294359c4250aac8560f2510bf0d0a8b1.zip
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.
Diffstat (limited to 'src/obswebsocket.cr')
-rw-r--r--src/obswebsocket.cr13
1 files 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