Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions internal/doltserver/doltserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,6 @@ func EnsureRunning(beadsDir string) (int, error) {
return state.Port, nil
}

// Clean up orphaned dolt sql-server processes before starting a new one.
// Without this, servers accumulate when parent processes crash or are
// force-killed without graceful shutdown (GH#2372).
if killed, err := KillStaleServers(serverDir); err == nil && len(killed) > 0 {
fmt.Fprintf(os.Stderr, "Info: cleaned up %d orphaned dolt sql-server process(es)\n", len(killed))
}

s, err := Start(serverDir)
if err != nil {
return 0, err
Expand Down Expand Up @@ -495,6 +488,15 @@ func Start(beadsDir string) (*State, error) {
return state, nil
}

// Clean up orphaned dolt sql-server processes INSIDE the lock.
// This MUST happen under the lock to prevent a race where one process
// kills a server that another process is in the middle of starting
// (PID file not yet written). Without this, concurrent bd processes
// can cause journal corruption (GH#2430).
if killed, killErr := KillStaleServers(beadsDir); killErr == nil && len(killed) > 0 {
fmt.Fprintf(os.Stderr, "Info: cleaned up %d orphaned dolt sql-server process(es)\n", len(killed))
}

// Ensure dolt binary exists
doltBin, err := exec.LookPath("dolt")
if err != nil {
Expand Down
Loading