fix: resolve MemStore timestamp overflow causing immediate message expiry

DateTime.UtcNow.Ticks * 100L overflows long (Ticks ~6.38e17, x100 =
6.38e19 > long.MaxValue 9.22e18), producing corrupted timestamps that
cause PruneExpiredMessages to immediately expire all messages when
MaxAgeMs is set. Use Unix epoch offset to match Go's time.Now().UnixNano().
This commit is contained in:
Joseph Doherty
2026-02-24 23:08:39 -05:00
parent 8fcf27af5b
commit 13a3f81d7e
2 changed files with 21 additions and 15 deletions

View File

@@ -426,8 +426,8 @@ public sealed class StoreInterfaceTests
for (var seq = 4UL; seq <= 7UL; seq++)
s.RemoveMsg(seq).ShouldBeTrue();
// Convert nanoseconds timestamp to DateTime.
var t = new DateTime(startTs / 100L, DateTimeKind.Utc);
// Convert Unix nanoseconds timestamp to DateTime.
var t = new DateTime(startTs / 100L + DateTime.UnixEpoch.Ticks, DateTimeKind.Utc);
var found = s.GetSeqFromTime(t);
found.ShouldBe(2UL);
}
@@ -454,7 +454,7 @@ public sealed class StoreInterfaceTests
// Delete last message — trailing delete.
s.RemoveMsg(3).ShouldBeTrue();
var t = new DateTime(startTs / 100L, DateTimeKind.Utc);
var t = new DateTime(startTs / 100L + DateTime.UnixEpoch.Ticks, DateTimeKind.Utc);
var found = s.GetSeqFromTime(t);
found.ShouldBe(2UL);
}