Skip to content

Commit 602e13b

Browse files
authored
fix: re-attempt Users.Update() if it fails due to a Collection was modified error (AscensionGameDev#2102)
* fix: re-attempt Users.Update() if it fails due to a Collection was modified error * log warning when it successfully recovers * AggregateException message
1 parent b0b59c8 commit 602e13b

File tree

1 file changed

+29
-1
lines changed
  • Intersect.Server.Core/Database/PlayerData

1 file changed

+29
-1
lines changed

Intersect.Server.Core/Database/PlayerData/User.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,35 @@ private UserSaveResult Save(PlayerContext? playerContext, bool force = false, bo
370370
else
371371
{
372372
// playerContext.Attach(this);
373-
playerContext.Users.Update(this);
373+
try
374+
{
375+
playerContext.Users.Update(this);
376+
}
377+
catch (InvalidOperationException invalidOperationException)
378+
{
379+
// ReSharper disable once ConstantConditionalAccessQualifier
380+
// ReSharper disable once ConstantNullCoalescingCondition
381+
if (invalidOperationException.Message?.Contains("Collection was modified") ?? false)
382+
{
383+
try
384+
{
385+
playerContext.Users.Update(this);
386+
Log.Warn(invalidOperationException, $"Successfully recovered from {nameof(InvalidOperationException)}");
387+
}
388+
catch (Exception exception)
389+
{
390+
throw new AggregateException(
391+
$"Failed to recover from {nameof(InvalidOperationException)}",
392+
invalidOperationException,
393+
exception
394+
);
395+
}
396+
}
397+
else
398+
{
399+
throw;
400+
}
401+
}
374402
}
375403

376404
playerContext.ChangeTracker.DetectChanges();

0 commit comments

Comments
 (0)