Skip to content

Let bootstrap shutdown exit standalone server#930

Merged
notfood merged 1 commit into
rwmt:devfrom
MhaWay:fix-bootstrap-server-shutdown
May 20, 2026
Merged

Let bootstrap shutdown exit standalone server#930
notfood merged 1 commit into
rwmt:devfrom
MhaWay:fix-bootstrap-server-shutdown

Conversation

@MhaWay
Copy link
Copy Markdown
Contributor

@MhaWay MhaWay commented May 19, 2026

Summary

  • make the standalone server process exit cleanly after bootstrap writes save.zip
  • avoid blocking the main loop on Console.ReadLine while the server has already requested shutdown
  • keep the fix limited to shutdown behavior without changing bootstrap/server restart semantics

Testing

  • dotnet publish .\Server\Server.csproj --configuration Release --runtime win-x64 --self-contained false -p:UseAppHost=true -o ..\artifacts\live-test-server\Windows
  • manual bootstrap test confirming the process exits after "Bootstrap: wrote save.zip. Configuration complete; stopping server."

Copilot AI review requested due to automatic review settings May 19, 2026 21:32
@MhaWay
Copy link
Copy Markdown
Contributor Author

MhaWay commented May 19, 2026

fix, 1.6, standalone server

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Makes the standalone server's main loop responsive to server.running becoming false (e.g., after bootstrap writes save.zip and requests shutdown), so the process exits cleanly instead of blocking forever inside Console.ReadLine(). The fix replaces the blocking read with a polling loop driven by Console.KeyAvailable and Thread.Sleep(50).

Changes:

  • Add using System.Threading;.
  • Wrap Console.ReadLine() in a Console.KeyAvailable check so the loop can re-evaluate server.running periodically.
  • Sleep 50 ms between polls when no input is pending.
Comments suppressed due to low confidence (1)

Source/Server/Server.cs:134

  • Console.KeyAvailable throws InvalidOperationException whenever standard input is redirected (e.g., the server is run with piped stdin, launched as a background/detached process, run under a service manager, or under a CI/test harness). The previous Console.ReadLine() worked in those scenarios — it simply blocked or returned null on EOF. As written, this loop will crash on the very first iteration in any non-interactive deployment, which is a regression for headless server use.

Consider gating the polling on Console.IsInputRedirected (falling back to a blocking read, or skipping console command handling entirely) so redirected/non-interactive stdin doesn't break the main loop. A blocking ReadLine on a dedicated input thread that enqueues commands is another common pattern that avoids both the busy-wait and the redirection problem.

    if (Console.KeyAvailable)
    {
        var cmd = Console.ReadLine();
        if (cmd != null)
            server.Enqueue(() => server.HandleChatCmd(consoleSource, cmd));

        if (cmd == stopCmd)
            break;
    }
    else
    {
        Thread.Sleep(50);
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Source/Server/Server.cs
Comment on lines 120 to 135
while (server.running)
{
var cmd = Console.ReadLine();
if (cmd != null)
server.Enqueue(() => server.HandleChatCmd(consoleSource, cmd));
if (Console.KeyAvailable)
{
var cmd = Console.ReadLine();
if (cmd != null)
server.Enqueue(() => server.HandleChatCmd(consoleSource, cmd));

if (cmd == stopCmd)
break;
if (cmd == stopCmd)
break;
}
else
{
Thread.Sleep(50);
}
}
@notfood notfood added fix Fixes for a bug or desync. 1.6 Fixes or bugs relating to 1.6 (Not Odyssey). standalone server Fix or bugs relating to the standalone server. labels May 19, 2026
@notfood notfood moved this to In review in 1.6 and Odyssey May 19, 2026
Copy link
Copy Markdown
Member

@mibac138 mibac138 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally we'd probably want to read the console in another thread and the main thread can then only block until the server is not running anymore, but this is fine for a simple fix

@notfood notfood merged commit 2f856bb into rwmt:dev May 20, 2026
4 of 5 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in 1.6 and Odyssey May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.6 Fixes or bugs relating to 1.6 (Not Odyssey). fix Fixes for a bug or desync. standalone server Fix or bugs relating to the standalone server.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants