Skip to content

Commit e230be5

Browse files
fix(audience-http): propagate caller cancellation from SendBatchAsync
Addresses PR #701 review from @nattb8. The catch-filter branch for caller cancellation used to silently swallow the exception and let the method return `true` — its normal "batch sent, ask me again" signal. FlushAsync's send loop takes that return value at face value and immediately re-enters on the same cancelled token. HttpClient throws on entry (token still cancelled), the same branch swallows it, `true` is returned again. The batch is never deleted on this path, so ReadBatch keeps handing back the same events — a tight infinite loop. Rethrow instead. The caller's send loop exits via the exception; no behaviour change for HttpClient's internal timeout path (still filtered out by the `when (ct.IsCancellationRequested)` guard) so timeouts still trigger backoff. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e1ec7eb commit e230be5

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/Packages/Audience/Runtime/Transport/HttpTransport.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,15 @@ internal async Task<bool> SendBatchAsync(CancellationToken ct = default)
131131
}
132132
catch (OperationCanceledException) when (ct.IsCancellationRequested)
133133
{
134-
// Caller cancelled the token (e.g. on shutdown). Events stay on
135-
// disk, no failure recorded. HttpClient timeouts throw the same
136-
// exception but without ct.IsCancellationRequested set, so they
137-
// fall through to the Exception branch below and trigger backoff.
134+
// Caller cancelled the token (e.g. on shutdown). Events stay
135+
// on disk, no failure recorded. Rethrow so the caller's send
136+
// loop exits — swallowing here returns `true`, and the loop
137+
// would re-enter on the same cancelled token and spin because
138+
// the batch is still on disk. HttpClient timeouts throw the
139+
// same exception but without ct.IsCancellationRequested set,
140+
// so they fall through to the Exception branch below and
141+
// trigger backoff.
142+
throw;
138143
}
139144
catch (Exception ex)
140145
{

0 commit comments

Comments
 (0)