Skip to content

Capture and surface game server exit codes in LocalMultiplayerAgent#209

Draft
Copilot wants to merge 1 commit intomainfrom
copilot/add-exit-code-output
Draft

Capture and surface game server exit codes in LocalMultiplayerAgent#209
Copilot wants to merge 1 commit intomainfrom
copilot/add-exit-code-output

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

Game server exit codes were silently discarded. For containers, the code logged the exit code but never returned it. For processes, exit codes were never captured at all. This made it impossible to diagnose crashes or non-zero exits from the game server.

Interface changes

  • IProcessWrapper.WaitForProcessExit: voidint
  • ISessionHostRunner.WaitOnServerExit: TaskTask<int>
  • BaseSessionHostRunner abstract signature updated accordingly

ProcessWrapper: retain Process references to avoid GetProcessById pitfalls

Process.GetProcessById(pid) throws ArgumentException if the process has already exited, and is subject to PID reuse races. Both make exit code retrieval unreliable for short-lived or crashing servers.

ProcessWrapper now tracks started Process objects in a ConcurrentDictionary and retrieves them by ID in WaitForProcessExit, falling back to GetProcessById only for externally-started processes.

if (!_trackedProcesses.TryRemove(id, out Process process))
{
    process = Process.GetProcessById(id);
}
process.WaitForExit();
return process.ExitCode;

Runner implementations

  • ProcessRunner — returns and logs exit code from ProcessWrapper
  • DockerContainerEngine — returns ContainerWaitResponse.StatusCode (was already captured, just discarded)

MultiplayerServerManager

Captures the exit code and writes it to both logger and console:

Game server exited with exit code 1.

- IProcessWrapper.WaitForProcessExit now returns int (exit code)
- ProcessWrapper tracks started processes in ConcurrentDictionary for
  reliable exit code capture even when process crashes early
- ISessionHostRunner.WaitOnServerExit now returns Task<int>
- ProcessRunner and DockerContainerEngine return exit codes
- MultiplayerServerManager logs and prints the exit code to console

Agent-Logs-Url: https://github.com/PlayFab/MpsAgent/sessions/99f02fa0-80b5-470b-afbc-8b85cf45d9fa

Co-authored-by: dgkanatsios <8256138+dgkanatsios@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants