Skip to content

Commit e9523c3

Browse files
committed
make RESP3 detection more accurate "what was" rather than "what might have been"
1 parent 609ee96 commit e9523c3

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/StackExchange.Redis/PhysicalBridge.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,12 @@ public enum State : byte
124124
public RedisCommand LastCommand { get; private set; }
125125

126126
/// <summary>
127-
/// If we have a connection, report the protocol being used.
127+
/// If we have (or had) a connection, report the protocol being used.
128128
/// </summary>
129-
public RedisProtocol? Protocol => physical?.Protocol;
129+
/// <remarks>The value remains after disconnect, so that appropriate follow-up actions (pub/sub etc) can work reliably.</remarks>
130+
public RedisProtocol? Protocol => _protocol == 0 ? default(RedisProtocol?) : _protocol;
131+
private RedisProtocol _protocol; // note starts at zero, not RESP2
132+
internal void SetProtocol(RedisProtocol protocol) => _protocol = protocol;
130133

131134
public void Dispose()
132135
{

src/StackExchange.Redis/PhysicalConnection.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,11 @@ private enum ReadMode : byte
276276
private RedisProtocol _protocol; // note starts at **zero**, not RESP2
277277
public RedisProtocol? Protocol => _protocol == 0 ? null : _protocol;
278278

279-
internal void SetProtocol(RedisProtocol value) => _protocol = value;
279+
internal void SetProtocol(RedisProtocol value)
280+
{
281+
_protocol = value;
282+
BridgeCouldBeNull?.SetProtocol(value);
283+
}
280284

281285
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "Trust me yo")]
282286
internal void Shutdown()

src/StackExchange.Redis/ServerEndPoint.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,10 @@ internal void OnDisconnected(PhysicalBridge bridge)
636636
if (bridge == interactive)
637637
{
638638
CompletePendingConnectionMonitors("Disconnected");
639-
if (KnowOrAssumeResp3()) Multiplexer.UpdateSubscriptions();
639+
if (Protocol is RedisProtocol.Resp3)
640+
{
641+
Multiplexer.UpdateSubscriptions();
642+
}
640643
}
641644
else if (bridge == subscription)
642645
{

0 commit comments

Comments
 (0)