Skip to content

Commit 4a0d353

Browse files
committed
add tracking for "now" and "next" messages when recording message timeouts
1 parent 23ff71b commit 4a0d353

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/StackExchange.Redis/ExceptionFactory.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void add(string lk, string sk, string v)
217217
if (message.QueuePosition >= 0) add("QueuePosition", null, message.QueuePosition.ToString()); // the position the item was when added to the queue
218218
if ((int)message.ConnectionWriteState >= 0) add("WriteState", null, message.ConnectionWriteState.ToString()); // what the physical was doing when it was added to the queue
219219
#endif
220-
if (message.TryGetPhysicalState(out var ws, out var rs, out var sentDelta, out var receivedDelta))
220+
if (message != null && message.TryGetPhysicalState(out var ws, out var rs, out var sentDelta, out var receivedDelta))
221221
{
222222
add("Write-State", null, ws.ToString());
223223
add("Read-State", null, rs.ToString());
@@ -235,6 +235,13 @@ void add(string lk, string sk, string v)
235235
catch { }
236236
}
237237

238+
if (message != null)
239+
{
240+
message.TryGetHeadMessages(out var now, out var next);
241+
if (now != null) add("Message-Current", "active", mutiplexer.IncludeDetailInExceptions ? now.CommandAndKey : now.Command.ToString());
242+
if (next != null) add("Message-Next", "next", mutiplexer.IncludeDetailInExceptions ? next.CommandAndKey : next.Command.ToString());
243+
}
244+
238245
// Add server data, if we have it
239246
if (server != null)
240247
{

src/StackExchange.Redis/Message.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,15 @@ internal void SetEnqueued(PhysicalConnection connection)
647647
}
648648
}
649649

650-
internal bool TryGetPhysicalState(out PhysicalConnection.WriteStatus ws, out PhysicalConnection.ReadStatus rs, out long sentDelta, out long receivedDelta)
650+
internal void TryGetHeadMessages(out Message now, out Message next)
651+
{
652+
var connection = _enqueuedTo;
653+
now = next = null;
654+
if (connection != null) connection.GetHeadMessages(out now, out next);
655+
}
656+
657+
internal bool TryGetPhysicalState(out PhysicalConnection.WriteStatus ws, out PhysicalConnection.ReadStatus rs,
658+
out long sentDelta, out long receivedDelta)
651659
{
652660
var connection = _enqueuedTo;
653661
sentDelta = receivedDelta = -1;

src/StackExchange.Redis/PhysicalConnection.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,7 @@ private void MatchResult(in RawResult result)
14141414
throw new InvalidOperationException("Received response with no message waiting: " + result.ToString());
14151415
msg = _writtenAwaitingResponse.Dequeue();
14161416
}
1417+
_activeMessage = msg;
14171418

14181419
Trace("Response to: " + msg);
14191420
_readStatus = ReadStatus.ComputeResult;
@@ -1422,6 +1423,19 @@ private void MatchResult(in RawResult result)
14221423
_readStatus = ReadStatus.CompletePendingMessage;
14231424
msg.Complete();
14241425
}
1426+
1427+
_activeMessage = null;
1428+
}
1429+
1430+
private volatile Message _activeMessage;
1431+
1432+
internal void GetHeadMessages(out Message now, out Message next)
1433+
{
1434+
now = _activeMessage;
1435+
lock(_writtenAwaitingResponse)
1436+
{
1437+
next = _writtenAwaitingResponse.Count == 0 ? null : _writtenAwaitingResponse.Peek();
1438+
}
14251439
}
14261440

14271441
partial void OnCloseEcho();

0 commit comments

Comments
 (0)