Skip to content

Commit e9b2af9

Browse files
committed
fix(duckdb): properly kill process to prevent blocking queries
Extract process killing logic into a dedicated `kill()` method that marks the connection as disconnected before killing the process. Call this method on pipe errors during query execution and during connection close to ensure that a dead or unresponsive DuckDB process does not block subsequent queries.
1 parent d85aecd commit e9b2af9

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

core/dbio/iop/duckdb.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,22 @@ func (duck *DuckDb) Close() error {
511511
case <-timer.C:
512512
if duck.Proc.Cmd != nil {
513513
g.Debug("killing pid %s", duck.Proc.Cmd.Process.Pid)
514-
duck.Proc.Cmd.Process.Kill()
514+
duck.kill()
515515
}
516516
}
517517
duck.Proc.Cmd = nil
518518

519519
return nil
520520
}
521521

522+
// kill kills the DuckDB process to abort an in-flight query; the next query re-opens a fresh process
523+
func (duck *DuckDb) kill() {
524+
duck.SetProp("connected", "false")
525+
if duck.Proc != nil && duck.Proc.Cmd != nil && duck.Proc.Cmd.Process != nil {
526+
duck.Proc.Cmd.Process.Kill()
527+
}
528+
}
529+
522530
// Exec executes a SQL query and returns the result
523531
func (duck *DuckDb) Exec(sql string, args ...any) (result sql.Result, err error) {
524532

@@ -708,6 +716,7 @@ func (duck *DuckDb) newQuery(ctx context.Context, sql string) (query *duckDbQuer
708716
dq.err = err
709717
dq.writer.CloseWithError(err)
710718
dq.reader.CloseWithError(err)
719+
duck.kill() // kill the proc so it won't block subsequent queries
711720
return
712721
case <-ticker.C:
713722
if duck.Proc != nil && !dq.done && (duck.Proc.Exited() || duck.Proc.ScanErr != nil) {

0 commit comments

Comments
 (0)