Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Content.Server/Corvax/Sponsors/SponsorsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void InvalidateCache(NetUserId userId)

try
{
var data = await FetchSponsorDataAsync(userId, CancellationToken.None);
var data = await FetchSponsorDataAsync(userId, CancellationToken.None).ConfigureAwait(false);
lock (_cacheLock)
_cache[userId] = new CachedSponsor(data, DateTime.UtcNow + CacheDuration);
return data;
Expand All @@ -177,15 +177,17 @@ public void InvalidateCache(NetUserId userId)
}

var url = $"{_apiUrl.TrimEnd('/')}/api/sponsors/{userId.UserId}";
var response = await _httpClient.GetAsync(url, cancel);
// GetCachedOrFetch uses GetResult() on the main thread; ConfigureAwait(false) avoids sync-context deadlock.
var response = await _httpClient.GetAsync(url, cancel).ConfigureAwait(false);

if (!response.IsSuccessStatusCode)
{
_sawmill.Warning($"Sponsor API returned {response.StatusCode} for {userId}");
return null;
}

return await response.Content.ReadFromJsonAsync<SponsorApiResponse>();
return await response.Content.ReadFromJsonAsync<SponsorApiResponse>(cancellationToken: cancel)
.ConfigureAwait(false);
}

private sealed record CachedSponsor(SponsorApiResponse? Data, DateTime ExpiresAt);
Expand Down
Loading