diff --git a/.github/workflows/ogl-net10-shutdown.yml b/.github/workflows/ogl-net10-shutdown.yml index 0042b263..7bded364 100644 --- a/.github/workflows/ogl-net10-shutdown.yml +++ b/.github/workflows/ogl-net10-shutdown.yml @@ -8,6 +8,9 @@ on: - 'OpenSim/Region/Framework/Scenes/SceneManager.cs' - 'OpenSim/Region/Framework/Scenes/Scene.cs' - 'OpenSim/Region/Application/OpenSimBase.cs' + - 'OpenSim/Region/Application/Application.cs' + - 'OpenSim/Framework/Servers/ServerBase.cs' + - 'OpenSim/Framework/Servers/BaseOpenSimServer.cs' - 'OpenSim/Region/Application/OpenSimBackground.cs' - 'tools/ci/Net10ShutdownRegression/**' - 'tools/ci/verify_net10_shutdown.py' diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs index 940713b1..484971c1 100644 --- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs +++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs @@ -57,6 +57,12 @@ namespace OpenSim.Framework.Servers /// public bool SuppressExit { get; set; } + /// + /// Allows region hosts to report incomplete persistence and failed cleanup + /// as a nonzero exit to systemd, instead of always signaling success. + /// + protected int ShutdownExitCode { get; set; } + /// /// This will control a periodic log printout of the current 'show stats' (if they are active) for this /// server. @@ -145,7 +151,7 @@ namespace OpenSim.Framework.Servers m_log.Info("[SHUTDOWN]: Shutdown processing on main thread complete. Exiting..."); if (!SuppressExit) - Environment.Exit(0); + Environment.Exit(ShutdownExitCode); } /// diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs index e5550598..c6a44cb5 100644 --- a/OpenSim/Framework/Servers/ServerBase.cs +++ b/OpenSim/Framework/Servers/ServerBase.cs @@ -51,6 +51,13 @@ namespace OpenSim.Framework.Servers public IConfigSource Config { get; protected set; } + private int m_shutdownRequested; + + /// + /// Used by the host console to stop prompting after quit/shutdown. + /// + public bool ShutdownRequested => Volatile.Read(ref m_shutdownRequested) != 0; + /// /// Console to be used for any command line output. Can be null, in which case there should be no output. /// @@ -977,6 +984,7 @@ namespace OpenSim.Framework.Servers public virtual void Shutdown() { + Interlocked.Exchange(ref m_shutdownRequested, 1); m_serverStatsCollector.Close(); ShutdownSpecific(); } diff --git a/OpenSim/Region/Application/Application.cs b/OpenSim/Region/Application/Application.cs index 4fe8bdaf..a054b2fd 100644 --- a/OpenSim/Region/Application/Application.cs +++ b/OpenSim/Region/Application/Application.cs @@ -303,7 +303,7 @@ namespace OpenSim m_sim.Startup(); - while (true) + while (!m_sim.ShutdownRequested) { try { diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index c3b61d40..224ad671 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -1006,10 +1006,12 @@ namespace OpenSim Config?.Configs["OGLShutdown"]?.GetInt("RegionCloseTimeoutSeconds", 180) ?? 180, 0, 3600); try { - SceneManager.Close(regionCloseTimeoutSeconds); + if (!SceneManager.Close(regionCloseTimeoutSeconds)) + ShutdownExitCode = 1; } catch (Exception e) { + ShutdownExitCode = 1; m_log.Error("[OGL SHUTDOWN]: Scene manager failed; attempting plugin cleanup regardless.", e); } @@ -1018,6 +1020,7 @@ namespace OpenSim try { plugin.Dispose(); } catch (Exception e) { + ShutdownExitCode = 1; m_log.Error("[OGL SHUTDOWN]: Failed to dispose plugin " + plugin.GetType().FullName, e); } } diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs index dffcc66e..6ff34ee3 100644 --- a/OpenSim/Region/Framework/Scenes/SceneManager.cs +++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs @@ -148,7 +148,7 @@ namespace OpenSim.Region.Framework.Scenes /// continues closing on a background thread and its unsaved state may be lost /// when the process exits. Use systemd's stop timeout as a second watchdog. /// - public void Close(int regionCloseTimeoutSeconds = 0) + public bool Close(int regionCloseTimeoutSeconds = 0) { List localScenes; lock (m_localScenes) @@ -207,6 +207,8 @@ namespace OpenSim.Region.Framework.Scenes m_log.ErrorFormat("[OGL SHUTDOWN]: {0} of {1} region close operations failed or timed out; check backups before restarting.", failed, localScenes.Count); else m_log.InfoFormat("[OGL SHUTDOWN]: All {0} region close operations completed.", localScenes.Count); + + return failed == 0; } public void Close(Scene cscene) diff --git a/doc/GEN1_NET10_SHUTDOWN_KEYFRAME.md b/doc/GEN1_NET10_SHUTDOWN_KEYFRAME.md index 70d6058a..2c454692 100644 --- a/doc/GEN1_NET10_SHUTDOWN_KEYFRAME.md +++ b/doc/GEN1_NET10_SHUTDOWN_KEYFRAME.md @@ -52,3 +52,14 @@ still needs an in-world high-churn stress test. base shutdown completed. The completion event is now signalled from a `finally` block **after** application cleanup, preventing the main thread from treating an in-progress shutdown as completed. + +## Shutdown service exit status and console loop + +`SceneManager.Close(int)` now reports a boolean result. A scene timeout, +exception or plugin-disposal failure marks the simulator's exit status nonzero +instead of falsely reporting success to systemd. This does not recover unsaved +data; operators must inspect failed region names before restarting. + +The console command loop stops requesting new prompts after a shutdown +request. The normal process still exits through the inherited server shutdown +handler after cleanup. diff --git a/tools/ci/Net10ShutdownRegression/Program.cs b/tools/ci/Net10ShutdownRegression/Program.cs index 82db49a9..a06100e1 100644 --- a/tools/ci/Net10ShutdownRegression/Program.cs +++ b/tools/ci/Net10ShutdownRegression/Program.cs @@ -53,3 +53,6 @@ ack.Remove(123); ack.Clear(); Assert(ack.Count() == 0, "ACK queue tolerates late callback and repeated close"); Console.WriteLine("PASS: .NET 10 OGKF serialization, legacy preservation and UDP teardown regression"); + +Assert(typeof(SceneManager).GetMethod("Close", new[] { typeof(int) })!.ReturnType == typeof(bool), + "region shutdown reports success/failure"); diff --git a/tools/ci/verify_net10_shutdown.py b/tools/ci/verify_net10_shutdown.py index 5ecc8de7..a759e021 100644 --- a/tools/ci/verify_net10_shutdown.py +++ b/tools/ci/verify_net10_shutdown.py @@ -15,6 +15,15 @@ assert "IsBackground = true" in scenes assert "scene.Close();" in scenes assert "plugin.Dispose()" in base assert "SceneManager.Close(regionCloseTimeoutSeconds)" in base +assert "if (!SceneManager.Close(regionCloseTimeoutSeconds))" in base +assert "ShutdownExitCode = 1;" in base +assert "return failed == 0;" in scenes +server = (root / "OpenSim/Framework/Servers/BaseOpenSimServer.cs").read_text() +assert "Environment.Exit(ShutdownExitCode)" in server +host = (root / "OpenSim/Framework/Servers/ServerBase.cs").read_text() +app = (root / "OpenSim/Region/Application/Application.cs").read_text() +assert "public bool ShutdownRequested" in host +assert "while (!m_sim.ShutdownRequested)" in app background = (root / "OpenSim/Region/Application/OpenSimBackground.cs").read_text() shutdown = background.split("public override void Shutdown()", 1)[1] assert shutdown.index("base.Shutdown();") < shutdown.index("WorldHasComeToAnEnd.Set();")