/internal/storage/dolt: fix windows build issue

This commit is contained in:
Test
2026-01-21 13:59:47 -08:00
parent 0a9bcc2dd0
commit 7670112341
5 changed files with 91 additions and 27 deletions

View File

@@ -15,7 +15,6 @@ import (
"strconv"
"strings"
"sync"
"syscall"
"time"
)
@@ -107,10 +106,8 @@ func (s *Server) Start(ctx context.Context) error {
s.cmd = exec.CommandContext(ctx, "dolt", args...)
s.cmd.Dir = s.cfg.DataDir
// Set up process group for clean shutdown
s.cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
}
// Set up process group for clean shutdown (Unix-only; no-op on Windows).
setDoltServerSysProcAttr(s.cmd)
// Set up logging
if s.cfg.LogFile != "" {
@@ -163,13 +160,8 @@ func (s *Server) Stop() error {
return nil
}
// Try graceful shutdown first (SIGTERM)
if err := s.cmd.Process.Signal(syscall.SIGTERM); err != nil {
// Process may already be dead
if !strings.Contains(err.Error(), "process already finished") {
return fmt.Errorf("failed to send SIGTERM: %w", err)
}
}
// Best-effort graceful shutdown (platform-specific).
_ = terminateProcess(s.cmd.Process)
// Wait for graceful shutdown with timeout
done := make(chan error, 1)
@@ -250,11 +242,9 @@ func (s *Server) waitForReady(ctx context.Context) error {
default:
}
// Check if process is still alive using signal 0
if s.cmd.Process != nil {
if err := s.cmd.Process.Signal(syscall.Signal(0)); err != nil {
return fmt.Errorf("server process exited unexpectedly")
}
// Best-effort: if we can tell the process is dead, fail fast.
if s.cmd.Process != nil && !processMayBeAlive(s.cmd.Process) {
return fmt.Errorf("server process exited unexpectedly")
}
// Try to connect
@@ -290,9 +280,8 @@ func GetRunningServerPID(dataDir string) int {
return 0
}
// On Unix, FindProcess always succeeds, so we need to check if it's alive
if err := process.Signal(syscall.Signal(0)); err != nil {
// Process is not running
// Best-effort liveness check (platform-specific).
if !processMayBeAlive(process) {
_ = os.Remove(pidFile)
return 0
}
@@ -307,13 +296,8 @@ func StopServerByPID(pid int) error {
return err
}
// Try graceful shutdown first
if err := process.Signal(syscall.SIGTERM); err != nil {
if !strings.Contains(err.Error(), "process already finished") {
return err
}
return nil
}
// Best-effort graceful shutdown (platform-specific).
_ = terminateProcess(process)
// Wait for graceful shutdown
done := make(chan struct{})