1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-05 13:36:30 +03:00

Handle temporary files being present when loading guild data (#345)

This PR fixes catastrophic guild data loading errors that appear when
there are lingering temporary files. In normal operation, temporary
files are deleted as soon as they are copied to the main file. It is
also expected that temporary files are valid JSON files.

However, due to a yesterday's DoS attack, something™️ happened and a
bunch of empty temporary files got written to disk. When Octobot
recovered from the attack, it was unable to load any guild data because
of the temporary files.

This PR addresses this issue by changing the data loading logic:
1) Check if there's a temporary file. If it exists, try loading it.
2) If it is successfully loaded, move the temp file to the main file and
resume operation as normal
3) If it could not be loaded, try loading the main file
4) If it is successfully loaded, delete the temporary file and resume
operation as normal
5) If it is not, throw an error (like before)

This PR was tested on production data and managed to load every guild
without errors.

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2025-02-03 16:58:57 +05:00 committed by GitHub
parent bf818401d8
commit 4785d162a2
Signed by: GitHub
GPG key ID: B5690EEEBB952194
2 changed files with 144 additions and 47 deletions

View file

@ -10,7 +10,7 @@ public static class GuildScheduledEventExtensions
out string? location)
{
endTime = default;
location = default;
location = null;
if (!scheduledEvent.EntityMetadata.AsOptional().IsDefined(out var metadata))
{
return new ArgumentNullError(nameof(scheduledEvent.EntityMetadata));