Reset heartbeat timer after triggering a reconnect

This commit is contained in:
James Allen 2014-11-19 11:25:09 +00:00
parent b67b49564d
commit db3537a8eb

View file

@ -39,10 +39,12 @@ module.exports = RedisSharelatex =
lastHeartbeat = Date.now() lastHeartbeat = Date.now()
reconnectIfInactive = () -> reconnectIfInactive = () ->
timeSinceLastHeartBeat = Date.now() - lastHeartbeat timeSinceLastHeartbeat = Date.now() - lastHeartbeat
if timeSinceLastHeartBeat > reconnectAfter if timeSinceLastHeartbeat > reconnectAfter
console.warn "No heartbeat for #{timeSinceLastHeartBeat}ms, reconnecting" console.warn "No heartbeat for #{timeSinceLastHeartbeat}ms, reconnecting"
sub.connection_gone("no heartbeat for #{timeSinceLastHeartBeat}ms") sub.connection_gone("no heartbeat for #{timeSinceLastHeartbeat}ms")
# Reset timer after triggering a reconnect to avoid potential cascading failure.
lastHeartbeat = Date.now()
setInterval () -> setInterval () ->
pub.publish heartbeatChannel, "PING" pub.publish heartbeatChannel, "PING"