Skip to content

Commit

Permalink
AutoConfigure detects protocol failure HeartBeats don't prevent repli…
Browse files Browse the repository at this point in the history
…ca reconfig
  • Loading branch information
leachdaniel-clark committed Aug 24, 2024
1 parent fe40d17 commit e2c623e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/StackExchange.Redis/PhysicalBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,20 +610,20 @@ internal void OnHeartbeat(bool ifConnectedOnly)
checkConfigSeconds = ServerEndPoint.ConfigCheckSeconds;

if (state == (int)State.ConnectedEstablished && ConnectionType == ConnectionType.Interactive
&& tmp.BridgeCouldBeNull?.Multiplexer.RawConfig.HeartbeatConsistencyChecks == true)
&& checkConfigSeconds > 0 && ServerEndPoint.LastInfoReplicationCheckSecondsAgo >= checkConfigSeconds
&& ServerEndPoint.CheckInfoReplication())
{
// that serves as a keep-alive, if it is accepted
}
else if (state == (int)State.ConnectedEstablished && ConnectionType == ConnectionType.Interactive
&& tmp.BridgeCouldBeNull?.Multiplexer.RawConfig.HeartbeatConsistencyChecks == true)
{
// If HeartbeatConsistencyChecks are enabled, we're sending a PING (expecting PONG) or ECHO (expecting UniqueID back) every single
// heartbeat as an opt-in measure to react to any network stream drop ASAP to terminate the connection as faulted.
// If we don't get the expected response to that command, then the connection is terminated.
// This is to prevent the case of things like 100% string command usage where a protocol error isn't otherwise encountered.
KeepAlive(forceRun: true);
}
else if (state == (int)State.ConnectedEstablished && ConnectionType == ConnectionType.Interactive
&& checkConfigSeconds > 0 && ServerEndPoint.LastInfoReplicationCheckSecondsAgo >= checkConfigSeconds
&& ServerEndPoint.CheckInfoReplication())
{
// that serves as a keep-alive, if it is accepted
}
else if (writeEverySeconds > 0 && tmp.LastWriteSecondsAgo >= writeEverySeconds)
{
Trace("OnHeartbeat - overdue");
Expand Down
13 changes: 12 additions & 1 deletion src/StackExchange.Redis/ResultProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,20 @@ public override bool SetResult(PhysicalConnection connection, Message message, i
Log?.LogInformation($"{Format.ToString(server)}: Auto-configured role: replica");
server.IsReplica = true;
}

return base.SetResult(connection, message, result);
}

return base.SetResult(connection, message, result);
var success = base.SetResult(connection, message, result);

if (!success && connection.BridgeCouldBeNull?.IsConnected == true)
{
connection.RecordConnectionFailed(
ConnectionFailureType.ProtocolFailure,
new InvalidOperationException($"unexpected auto-configure reply to {message.Command}: {result.ToString()}"));
}

return success;
}

protected override bool SetResultCore(PhysicalConnection connection, Message message, in RawResult result)
Expand Down

0 comments on commit e2c623e

Please sign in to comment.