Fix control pipe accept loop: create instances only after a client connects; CLI force-update never touches the service log file

This commit is contained in:
mram
2026-09-22 08:43:58 +02:00
parent 09d4e81eab
commit c7b8747d85
2 changed files with 14 additions and 12 deletions
+4
View File
@@ -362,6 +362,10 @@ func forceUpdateCommand(configPath string, elevatedChild bool) int {
fmt.Fprintf(os.Stderr, "gpu-turnstile: cannot locate executable: %v\n", err) fmt.Fprintf(os.Stderr, "gpu-turnstile: cannot locate executable: %v\n", err)
return 1 return 1
} }
// One-shot CLI: the updater logs to stderr, never to the service's
// LOG_FILE — that file is ACL'd to the service account, and a CLI run
// has nothing worth persisting there.
cfg.LogFile = ""
log, _, logCloser := newLogger(cfg) log, _, logCloser := newLogger(cfg)
defer logCloser.Close() defer logCloser.Close()
if cfg.AppVersion == "dev" { if cfg.AppVersion == "dev" {
+10 -12
View File
@@ -77,18 +77,16 @@ func Serve(ctx context.Context, h Handler, log *slog.Logger) error {
log.Warn("control channel stopped", "err", err) log.Warn("control channel stopped", "err", err)
return return
} }
go func() { // Blocks until a client connects — only then is the next
// Blocks until a client connects; on process exit the // instance created, so instances are not burned without
// handle goes away with everything else. A client that // clients. ERROR_PIPE_CONNECTED means the client raced us
// raced us and connected between CreateNamedPipe and // and connected before the call: that is a success. Process
// ConnectNamedPipe reports ERROR_PIPE_CONNECTED — that is // exit reaps the blocked call on shutdown.
// a success, not a failure. if err := windows.ConnectNamedPipe(pipe, nil); err != nil && err != errnoPipeConnected {
if err := windows.ConnectNamedPipe(pipe, nil); err != nil && err != errnoPipeConnected { windows.CloseHandle(pipe)
windows.CloseHandle(pipe) continue
return }
} go serveConn(&pipeConn{f: os.NewFile(uintptr(pipe), pipePath), h: pipe}, h)
serveConn(&pipeConn{f: os.NewFile(uintptr(pipe), pipePath), h: pipe}, h)
}()
} }
}() }()
return nil return nil