From b25cde9984219844561ccb523da0500c8d29af58 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Thu, 21 Jul 2022 08:16:59 -0700 Subject: [PATCH] sql: fix recent leak of a context Release note: None --- pkg/sql/conn_executor_exec.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/sql/conn_executor_exec.go b/pkg/sql/conn_executor_exec.go index 9e6e4b02a1b2..d2d041f2c6a4 100644 --- a/pkg/sql/conn_executor_exec.go +++ b/pkg/sql/conn_executor_exec.go @@ -281,6 +281,10 @@ func (ex *connExecutor) execStmtInOpenState( var cancelQuery context.CancelFunc ctx, cancelQuery = contextutil.WithCancel(ctx) + // When we exit this method, the execution flow must have finished, so + // canceling the context here is safe. This cancellation is needed to + // prevent a leak of the context. + defer cancelQuery() makeErrEvent := func(err error) (fsm.Event, fsm.EventPayload, error) { ev, payload := ex.makeErrEvent(err, ast)