Skip to content

Commit d558fee

Browse files
authored
Merge pull request #903 from tursodatabase/turso-cli-dev-wait-sqld
wait for sqld process in the dev mode in order to capture unexpected exists (crashes, etc)
2 parents e8ece11 + 796cd4b commit d558fee

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

internal/cmd/dev.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,17 @@ var devCmd = &cobra.Command{
130130
} else {
131131
fmt.Printf("This server is using an ephemeral database. Changes will be lost when this server stops.\nIf you want to persist changes, use %s to specify a SQLite database file instead.\n", internal.Emph("--db-file"))
132132
}
133+
134+
waitCh := make(chan error, 1)
135+
go func() { waitCh <- sqld.Wait() }()
136+
133137
sigCh := make(chan os.Signal, 1)
134138
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
135-
<-sigCh
139+
select {
140+
case <-sigCh:
141+
case err = <-waitCh:
142+
return fmt.Errorf("sqld exited unexpectedly: %w", err)
143+
}
136144

137145
// Terminate the server process
138146
err = sqld.Process.Kill()
@@ -141,7 +149,7 @@ var devCmd = &cobra.Command{
141149
}
142150

143151
// Wait for the server process to exit.
144-
err = sqld.Wait()
152+
err = <-waitCh
145153
if err != nil {
146154
return fmt.Errorf("could not kill sqld: %w", err)
147155
}

0 commit comments

Comments
 (0)