Skip to content

Commit 9856ecf

Browse files
refactor(audience-sdk): name consent-sync retry budgets
Replaces the inline 4-attempt cap and 1-second base retry on the consent-sync PUT retry loop with named constants on ImmutableAudience so the budget is visible at the top of the class and a tuning change touches one place. - ImmutableAudience.cs: adds ConsentSyncMaxAttempts (4) and ConsentSyncBaseRetryMs (1000). - ImmutableAudience.cs: SyncConsentLevel uses ConsentSyncMaxAttempts and ConsentSyncBaseRetryMs in the 429 retry loop.
1 parent 6264a15 commit 9856ecf

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/Packages/Audience/Runtime/ImmutableAudience.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ public static class ImmutableAudience
2727
// teardown (Session.Dispose, timer drain, queue shutdown, transport
2828
// flush, disposes). This keeps the hold time to nanoseconds so a caller
2929
// arriving on a different thread is not stranded behind those budgets.
30+
// How many times we retry the consent-sync PUT after a 429.
31+
internal const int ConsentSyncMaxAttempts = 4;
32+
33+
// How long we wait before the first consent-sync retry. Doubles each time.
34+
internal const int ConsentSyncBaseRetryMs = 1_000;
35+
3036
private static AudienceConfig? _config;
3137
private static DiskStore? _store;
3238
private static EventQueue? _queue;
@@ -625,9 +631,9 @@ private static void SyncConsentToBackend(AudienceConfig config, ConsentLevel lev
625631

626632
Task.Run(async () =>
627633
{
628-
// 429 retried up to 4 attempts (1s/2s/4s or Retry-After).
629-
// Other non-2xx fail fast.
630-
const int maxAttempts = 4;
634+
// 429 retried up to ConsentSyncMaxAttempts attempts (1s/2s/4s
635+
// or Retry-After). Other non-2xx fail fast.
636+
const int maxAttempts = ConsentSyncMaxAttempts;
631637
var attempt = 0;
632638
try
633639
{
@@ -644,7 +650,7 @@ private static void SyncConsentToBackend(AudienceConfig config, ConsentLevel lev
644650
if (response.StatusCode == HttpStatusCode.TooManyRequests && attempt < maxAttempts)
645651
{
646652
var delay = HttpRetry.ParseRetryAfter(response)
647-
?? TimeSpan.FromMilliseconds(1_000 * (1 << (attempt - 1)));
653+
?? TimeSpan.FromMilliseconds(ConsentSyncBaseRetryMs * (1 << (attempt - 1)));
648654
await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
649655
continue;
650656
}

0 commit comments

Comments
 (0)