fix: Fixes libdeflate threading issue (#1813)
This commit is contained in:
parent
aeba2261d2
commit
a8d3d2773e
2 changed files with 8 additions and 11 deletions
|
|
@ -20,16 +20,8 @@ namespace Server.Compression;
|
||||||
|
|
||||||
public static class Deflate
|
public static class Deflate
|
||||||
{
|
{
|
||||||
public static LibDeflateBinding Standard { get; }
|
[ThreadStatic]
|
||||||
|
private static LibDeflateBinding _standard;
|
||||||
|
|
||||||
static Deflate()
|
public static LibDeflateBinding Standard => _standard ??= new LibDeflateBinding();
|
||||||
{
|
|
||||||
Standard = new LibDeflateBinding();
|
|
||||||
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Standard.Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Server.Compression;
|
||||||
using Server.Json;
|
using Server.Json;
|
||||||
using Server.Logging;
|
using Server.Logging;
|
||||||
using Server.Network;
|
using Server.Network;
|
||||||
|
|
@ -465,6 +466,10 @@ public static class Core
|
||||||
|
|
||||||
Console.CancelKeyPress += Console_CancelKeyPressed;
|
Console.CancelKeyPress += Console_CancelKeyPressed;
|
||||||
|
|
||||||
|
// LibDeflate is not thread safe, so we need to create a new instance for each thread
|
||||||
|
var standard = Deflate.Standard;
|
||||||
|
AppDomain.CurrentDomain.ProcessExit += (_, _) => standard.Dispose();
|
||||||
|
|
||||||
ServerConfiguration.Load();
|
ServerConfiguration.Load();
|
||||||
|
|
||||||
logger.Information("Running on {Framework}", RuntimeInformation.FrameworkDescription);
|
logger.Information("Running on {Framework}", RuntimeInformation.FrameworkDescription);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue