Skip to content

Commit b2a9596

Browse files
committed
Some more touchup of KeyExpired handler
1 parent 4a93ee7 commit b2a9596

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

API/Realtime/RedisSubscriberService.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,32 @@ public async Task StartAsync(CancellationToken cancellationToken)
5656

5757
private void HandleKeyExpired(RedisChannel _, RedisValue message)
5858
{
59-
if (!message.HasValue || message.IsNullOrEmpty)
59+
if (!message.HasValue)
6060
{
61-
_logger.LogDebug("Received expired key with emtpy value?? for hub offline status");
61+
_logger.LogWarning("Received expired key with empty value for hub offline status");
62+
return;
63+
}
64+
65+
var messageString = (string?)message;
66+
if (messageString is null)
67+
{
68+
_logger.LogWarning("Received expired key that could not be converted to string for hub offline status. Raw value type: {ValueType}", message.GetType().FullName);
6269
return;
6370
}
6471

65-
// ToString here just casts the underlying object to a string
66-
var messageString = message.ToString();
6772
var messageSpan = messageString.AsSpan();
6873

69-
// We always expect TypeName:GUID right now, and this wont throw if there is more split results than expected
70-
// We also dont need to check for its length after, since we pre-stackalloc
71-
Span<Range> split = stackalloc Range[2];
72-
messageSpan.Split(split, ':');
74+
// We always expect TypeName:GUID right now, if GUID is not present, something is really wrong
75+
var colonPos = messageSpan.IndexOf(':');
76+
if (colonPos < 0)
77+
{
78+
_logger.LogError("Received expired key with unexpected format (missing colon) for hub offline status. Value: {MessageValue}", messageString);
79+
return;
80+
}
7381

7482
// Data structure is TypeName:GUID
75-
var typeNameSpan = messageSpan[split[0]];
76-
var guidSpan = messageSpan[split[1]];
83+
var typeNameSpan = messageSpan[..colonPos];
84+
var guidSpan = messageSpan[(colonPos + 1)..];
7785

7886
// Check what type of expired key this is
7987
if (typeNameSpan.SequenceEqual(typeof(DeviceOnline).FullName))

0 commit comments

Comments
 (0)