Compare commits

..

1 Commits

Author SHA1 Message Date
zznty
83dfc7152f properly handle sigterm and dont freeze forever on unload 2023-07-13 13:18:20 +07:00
3 changed files with 17 additions and 4 deletions

View File

@@ -69,6 +69,14 @@ namespace Torch.Server
_simUpdateTimer.Elapsed += SimUpdateElapsed;
_simUpdateTimer.Start();
Console.CancelKeyPress += (_, _) =>
{
if (State == ServerState.Running)
Stop();
Environment.Exit(0);
};
}
private void SimUpdateElapsed(object sender, System.Timers.ElapsedEventArgs e)
@@ -239,9 +247,14 @@ namespace Torch.Server
StopInternal();
LogManager.Flush();
if (
#if DEBUG
Environment.Exit(0);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
true ||
#endif
ApplicationContext.Current.IsService
)
Environment.Exit(0);
var exe = Path.Combine(AppContext.BaseDirectory, "Torch.Server.exe");

View File

@@ -116,7 +116,7 @@ namespace Torch.Server
if (_server?.State == ServerState.Running)
_server.Stop();
Process.GetCurrentProcess().Kill();
Environment.Exit(0);
}
}
}

View File

@@ -372,10 +372,10 @@ namespace Torch
/// <inheritdoc />
public virtual void Stop()
{
LogManager.Flush();
Game.SignalStop();
if (!Game.WaitFor(VRageGame.GameState.Stopped))
if (!Game.WaitFor(VRageGame.GameState.Stopped, TimeSpan.FromSeconds(Config.TickTimeout)))
Log.Warn("Failed to wait for the game to be stopped");
LogManager.Flush();
}
/// <inheritdoc />