fix(server): keep the spawned server alive after the parent exits
Christian Rocha
and
Charm Crush
created
The parent process was creating the detached server via a context-bound
command, so when the parent exited or its context was cancelled the
runtime would also kill the brand new server we had just spawned. Drop
the context binding and rely on the existing platform-specific detach
to give the server a life of its own.
Co-Authored-By: Charm Crush <crush@charm.land>
@@ -569,7 +569,11 @@ func startDetachedServer(cmd *cobra.Command) error {
cmdArgs = append(cmdArgs, "--host", clientHost)
}
- c := exec.CommandContext(cmd.Context(), exe, cmdArgs...)
+ // Use exec.Command (not exec.CommandContext) so the parent's context
+ // cancellation does not kill the spawned server. detachProcess
+ // (Setsid on !windows, DETACHED_PROCESS on windows) is what truly
+ // detaches the child from this process's lifetime.
+ c := exec.Command(exe, cmdArgs...)
stdoutPath := filepath.Join(chDir, "stdout.log")
stderrPath := filepath.Join(chDir, "stderr.log")
detachProcess(c)