Correctly close context before attempting migration

This commit is contained in:
Dean Herbert 2021-01-21 19:02:09 +09:00
parent d2bf3a5805
commit 34a7ce912e
2 changed files with 12 additions and 6 deletions

View File

@ -1,6 +1,3 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Threading; using System.Threading;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -77,7 +74,7 @@ namespace osu.Game.Database
{ {
base.Update(); base.Update();
if (Context.Refresh()) if (context?.Refresh() == true)
refreshes.Value++; refreshes.Value++;
} }
@ -107,8 +104,7 @@ namespace osu.Game.Database
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
context?.Dispose(); FlushConnections();
context = null;
} }
/// <summary> /// <summary>
@ -152,5 +148,14 @@ namespace osu.Game.Database
pending_writes.Value--; pending_writes.Value--;
} }
} }
public void FlushConnections()
{
var previousContext = context;
context = null;
previousContext?.Dispose();
while (previousContext?.IsClosed == false)
Thread.Sleep(50);
}
} }
} }

View File

@ -513,6 +513,7 @@ namespace osu.Game
public void Migrate(string path) public void Migrate(string path)
{ {
contextFactory.FlushConnections(); contextFactory.FlushConnections();
realmFactory.FlushConnections();
(Storage as OsuStorage)?.Migrate(Host.GetStorage(path)); (Storage as OsuStorage)?.Migrate(Host.GetStorage(path));
} }
} }