From f3da876d6d8317537c55ab4a8819ca514710546a Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sat, 30 Sep 2023 20:41:46 +0500 Subject: [PATCH] Run scheduled event updates synchronously to avoid a rate limit error (#132) This PR attempts to fix this error: https://paste.gg/p/anonymous/358d5b1b80b44011b7afe5007270b175 based on the assumption that the error is caused by a race condition affecting the rate limit tracking code in Remora.Discord --- src/Services/Update/ScheduledEventUpdateService.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Services/Update/ScheduledEventUpdateService.cs b/src/Services/Update/ScheduledEventUpdateService.cs index f83c1de..f9aee51 100644 --- a/src/Services/Update/ScheduledEventUpdateService.cs +++ b/src/Services/Update/ScheduledEventUpdateService.cs @@ -34,20 +34,15 @@ public sealed class ScheduledEventUpdateService : BackgroundService protected override async Task ExecuteAsync(CancellationToken ct) { using var timer = new PeriodicTimer(TimeSpan.FromSeconds(1)); - var tasks = new List(); while (await timer.WaitForNextTickAsync(ct)) { var guildIds = _guildData.GetGuildIds(); - - tasks.AddRange(guildIds.Select(async id => + foreach (var id in guildIds) { var tickResult = await TickScheduledEventsAsync(id, ct); _logger.LogResult(tickResult, $"Error in scheduled events update for guild {id}."); - })); - - await Task.WhenAll(tasks); - tasks.Clear(); + } } }