mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 12:17:46 +08:00
Merge pull request #3279 from smoogipoo/fix-dbcontext-disposal
Fix threads being cross-disposed from DatabaseContextFactory
This commit is contained in:
commit
47ec139700
@ -5,7 +5,6 @@ using System;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.EntityFrameworkCore.Storage;
|
using Microsoft.EntityFrameworkCore.Storage;
|
||||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
@ -118,7 +117,9 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
private void recycleThreadContexts()
|
private void recycleThreadContexts()
|
||||||
{
|
{
|
||||||
threadContexts?.Values.ForEach(c => c.Dispose());
|
// Contexts for other threads are not disposed as they may be in use elsewhere. Instead, fresh contexts are exposed
|
||||||
|
// for other threads to use, and we rely on the finalizer inside OsuDbContext to handle their previous contexts
|
||||||
|
threadContexts?.Value.Dispose();
|
||||||
threadContexts = new ThreadLocal<OsuDbContext>(CreateContext, true);
|
threadContexts = new ThreadLocal<OsuDbContext>(CreateContext, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,13 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~OsuDbContext()
|
||||||
|
{
|
||||||
|
// DbContext does not contain a finalizer (https://github.com/aspnet/EntityFrameworkCore/issues/8872)
|
||||||
|
// This is used to clean up previous contexts when fresh contexts are exposed via DatabaseContextFactory
|
||||||
|
Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
base.OnConfiguring(optionsBuilder);
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
Loading…
Reference in New Issue
Block a user