File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -450,13 +450,6 @@ func EnsureRunning(beadsDir string) (int, error) {
450450 return state .Port , nil
451451 }
452452
453- // Clean up orphaned dolt sql-server processes before starting a new one.
454- // Without this, servers accumulate when parent processes crash or are
455- // force-killed without graceful shutdown (GH#2372).
456- if killed , err := KillStaleServers (serverDir ); err == nil && len (killed ) > 0 {
457- fmt .Fprintf (os .Stderr , "Info: cleaned up %d orphaned dolt sql-server process(es)\n " , len (killed ))
458- }
459-
460453 s , err := Start (serverDir )
461454 if err != nil {
462455 return 0 , err
@@ -506,6 +499,15 @@ func Start(beadsDir string) (*State, error) {
506499 return state , nil
507500 }
508501
502+ // Clean up orphaned dolt sql-server processes INSIDE the lock.
503+ // This MUST happen under the lock to prevent a race where one process
504+ // kills a server that another process is in the middle of starting
505+ // (PID file not yet written). Without this, concurrent bd processes
506+ // can cause journal corruption (GH#2430).
507+ if killed , killErr := KillStaleServers (beadsDir ); killErr == nil && len (killed ) > 0 {
508+ fmt .Fprintf (os .Stderr , "Info: cleaned up %d orphaned dolt sql-server process(es)\n " , len (killed ))
509+ }
510+
509511 // Ensure dolt binary exists
510512 doltBin , err := exec .LookPath ("dolt" )
511513 if err != nil {
You can’t perform that action at this time.
0 commit comments