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:
@@ -77,18 +77,16 @@ func Serve(ctx context.Context, h Handler, log *slog.Logger) error {
|
||||
log.Warn("control channel stopped", "err", err)
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
// Blocks until a client connects; on process exit the
|
||||
// handle goes away with everything else. A client that
|
||||
// raced us and connected between CreateNamedPipe and
|
||||
// ConnectNamedPipe reports ERROR_PIPE_CONNECTED — that is
|
||||
// a success, not a failure.
|
||||
if err := windows.ConnectNamedPipe(pipe, nil); err != nil && err != errnoPipeConnected {
|
||||
windows.CloseHandle(pipe)
|
||||
return
|
||||
}
|
||||
serveConn(&pipeConn{f: os.NewFile(uintptr(pipe), pipePath), h: pipe}, h)
|
||||
}()
|
||||
// Blocks until a client connects — only then is the next
|
||||
// instance created, so instances are not burned without
|
||||
// clients. ERROR_PIPE_CONNECTED means the client raced us
|
||||
// and connected before the call: that is a success. Process
|
||||
// exit reaps the blocked call on shutdown.
|
||||
if err := windows.ConnectNamedPipe(pipe, nil); err != nil && err != errnoPipeConnected {
|
||||
windows.CloseHandle(pipe)
|
||||
continue
|
||||
}
|
||||
go serveConn(&pipeConn{f: os.NewFile(uintptr(pipe), pipePath), h: pipe}, h)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user