|
@@ -41,17 +41,20 @@ module.exports = RedisSharelatex =
|
|
|
reconnectIfInactive = () ->
|
|
reconnectIfInactive = () ->
|
|
|
timeSinceLastHeartbeat = Date.now() - lastHeartbeat
|
|
timeSinceLastHeartbeat = Date.now() - lastHeartbeat
|
|
|
if timeSinceLastHeartbeat > reconnectAfter
|
|
if timeSinceLastHeartbeat > reconnectAfter
|
|
|
- console.warn "[#{new Date()}] No heartbeat for #{timeSinceLastHeartbeat}ms on #{heartbeatChannel}, reconnecting"
|
|
|
|
|
# If the client realises it isn't connected then will be trying to
|
|
# If the client realises it isn't connected then will be trying to
|
|
|
# restablish the connection, so there's nothing for us to do. If
|
|
# restablish the connection, so there's nothing for us to do. If
|
|
|
# it still thinks it's connected, then disconnect it and start to reconnect.
|
|
# it still thinks it's connected, then disconnect it and start to reconnect.
|
|
|
if sub.connected
|
|
if sub.connected
|
|
|
|
|
+ console.warn "[#{new Date()}] No heartbeat for #{timeSinceLastHeartbeat}ms on #{heartbeatChannel}, reconnecting"
|
|
|
sub.end()
|
|
sub.end()
|
|
|
# We ended the connection, but want to start it up again, so set
|
|
# We ended the connection, but want to start it up again, so set
|
|
|
# the internal closing variable:
|
|
# the internal closing variable:
|
|
|
sub.closing = false
|
|
sub.closing = false
|
|
|
- # Trigger the reconnect:
|
|
|
|
|
- sub.connection_gone("no heartbeat for #{timeSinceLastHeartbeat}ms")
|
|
|
|
|
|
|
+ # Trigger the reconnect (automatically triggered by sub.end() with closing = false):
|
|
|
|
|
+ # sub.connection_gone("no heartbeat for #{timeSinceLastHeartbeat}ms")
|
|
|
|
|
+ else
|
|
|
|
|
+ console.warn "[#{new Date()}] No heartbeat for #{timeSinceLastHeartbeat}ms on #{heartbeatChannel}, but not reconnecting (already reconnecting)"
|
|
|
|
|
+
|
|
|
# Reset timer after triggering a reconnect to avoid potential cascading failure.
|
|
# Reset timer after triggering a reconnect to avoid potential cascading failure.
|
|
|
lastHeartbeat = Date.now()
|
|
lastHeartbeat = Date.now()
|
|
|
|
|
|