Skip to content

Commit 0370279

Browse files
committed
sql: fix pausable portal cleanup stack behavior
We have several cleanup "stacks" for pausable portals model, but in reality previously we executed the functions in the "forward" direction, matching the behavior of a "queue", so this commit fixes that iterating over functions in reverse order. Only `dispatchToExecutionEngine` stage has multiple cleanup functions. Ensuring the correct order was necessary for the following commit which is what prompted this one. Additionally, we fix comments to reflect the reverse order of execution different cleanup stacks. Release note: None
1 parent 2452d33 commit 0370279

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pkg/sql/prepared_stmt.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ func (n *cleanupFuncStack) appendFunc(f func(context.Context)) {
188188
}
189189

190190
func (n *cleanupFuncStack) run(ctx context.Context) {
191-
for i := 0; i < len(n.stack); i++ {
191+
// Iterate in reverse order to simulate stack behavior.
192+
for i := len(n.stack) - 1; i >= 0; i-- {
192193
n.stack[i](ctx)
193194
}
194195
*n = cleanupFuncStack{}
@@ -226,18 +227,18 @@ type portalPauseInfo struct {
226227
// When closing a portal, we need to follow the reverse order of its execution,
227228
// which means running the cleanup functions of the four structs in the
228229
// following order:
229-
// - exhaustPortal.cleanup
230-
// - execStmtInOpenState.cleanup
231-
// - dispatchToExecutionEngine.cleanup
232230
// - resumableFlow.cleanup
231+
// - dispatchToExecutionEngine.cleanup
232+
// - execStmtInOpenState.cleanup
233+
// - exhaustPortal.cleanup
233234
//
234235
// If an error occurs in any of these functions, we run the cleanup functions of
235236
// this layer and its children layers, and propagate the error to the parent
236237
// layer. For example, if an error occurs in execStmtInOpenStateCleanup(), we
237238
// run the cleanup functions in the following order:
238-
// - execStmtInOpenState.cleanup
239-
// - dispatchToExecutionEngine.cleanup
240239
// - resumableFlow.cleanup
240+
// - dispatchToExecutionEngine.cleanup
241+
// - execStmtInOpenState.cleanup
241242
//
242243
// When exiting connExecutor.execStmtInOpenState(), we finally run the
243244
// exhaustPortal.cleanup function in connExecutor.execPortal().

0 commit comments

Comments
 (0)