Skip to content

Commit

Permalink
server/doltgres_handler.go: Ensure we run queries with the Context th…
Browse files Browse the repository at this point in the history
…at comes back from ProcessList.BeginQuery, so that we can cancel their contexts through the process list.
  • Loading branch information
reltuk committed Mar 6, 2025
1 parent 29e5d67 commit 30b5b17
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions server/doltgres_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,10 @@ func (h *DoltgresHandler) doQuery(ctx context.Context, c *mysql.Conn, query stri
sqlCtx.GetLogger().Debugf("Starting query")
sqlCtx.GetLogger().Tracef("beginning execution")

oCtx := ctx

// TODO: it would be nice to put this logic in the engine, not the handler, but we don't want the process to be
// marked done until we're done spooling rows over the wire
ctx, err = sqlCtx.ProcessList.BeginQuery(sqlCtx, query)
defer func() {
if err != nil && ctx != nil {
sqlCtx.ProcessList.EndQuery(sqlCtx)
}
}()
sqlCtx, err = sqlCtx.ProcessList.BeginQuery(sqlCtx, query)

Check failure on line 306 in server/doltgres_handler.go

View workflow job for this annotation

GitHub Actions / Run Staticcheck

this value of err is never used (SA4006)
defer sqlCtx.ProcessList.EndQuery(sqlCtx)

schema, rowIter, qFlags, err := queryExec(sqlCtx, query, parsed, analyzedPlan)
if err != nil {
Expand Down Expand Up @@ -341,9 +335,6 @@ func (h *DoltgresHandler) doQuery(ctx context.Context, c *mysql.Conn, query stri
return err
}

// errGroup context is now canceled
ctx = oCtx

sqlCtx.GetLogger().Debugf("Query finished in %d ms", time.Since(start).Milliseconds())

// processedAtLeastOneBatch means we already called callback() at least
Expand Down Expand Up @@ -528,7 +519,7 @@ func (h *DoltgresHandler) resultForDefaultIter(ctx *sql.Context, schema sql.Sche
for {
select {
case <-ctx.Done():
return nil
return context.Cause(ctx)
default:
row, err := iter.Next(ctx)
if err == io.EOF {
Expand Down Expand Up @@ -578,7 +569,7 @@ func (h *DoltgresHandler) resultForDefaultIter(ctx *sql.Context, schema sql.Sche

select {
case <-ctx.Done():
return nil
return context.Cause(ctx)
case row, ok := <-rowChan:
if !ok {
return nil
Expand Down

0 comments on commit 30b5b17

Please sign in to comment.