fix(health): acked SendAsync transport — report-loss counter restore is live, not dead code

This commit is contained in:
Joseph Doherty
2026-07-08 16:12:48 -04:00
parent 17af376a8e
commit 6300d6d399
5 changed files with 142 additions and 16 deletions
@@ -140,10 +140,13 @@ public class HealthReportSender : BackgroundService
var seq = Interlocked.Increment(ref _sequenceNumber);
// CollectReport atomically read-and-resets
// the per-interval error counters via Interlocked.Exchange. If
// the Send below throws, those counts are otherwise lost
// forever — neither in the un-sent report nor in the now-zeroed
// collector. Snapshot the freshly-collected report so that on a
// the per-interval error counters via Interlocked.Exchange. The
// transport is now an ACKED round-trip (SendAsync throws on
// timeout/nack — review 01 [Medium]), so this restore path is live
// rather than dead code. If the SendAsync below throws, those
// counts are otherwise lost forever — neither in the un-sent
// report nor in the now-zeroed collector. Snapshot the
// freshly-collected report so that on a
// transport failure we can atomically restore the counts back
// into the collector via Interlocked.Add, so the next
// successful report includes them. Concurrent increments
@@ -157,7 +160,7 @@ public class HealthReportSender : BackgroundService
try
{
_transport.Send(reportWithSeq);
await _transport.SendAsync(reportWithSeq, stoppingToken).ConfigureAwait(false);
}
catch
{