Add CHECK_FOR_INTERRUPTS in ExecInsert's speculative insertion loop.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 4 Aug 2022 18:10:06 +0000 (14:10 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 4 Aug 2022 18:10:06 +0000 (14:10 -0400)
Ordinarily the functions called in this loop ought to have plenty
of CFIs themselves; but we've now seen a case where no such CFI is
reached, making the loop uninterruptible.  Even though that's from
a recently-introduced bug, it seems prudent to install a CFI at
the loop level in all branches.

Per discussion of bug #17558 from Andrew Kesper (an actual fix for
that bug will follow).

Discussion: https://postgr.es/m/17558-3f6599ffcf52fd4a@postgresql.org

src/backend/executor/nodeModifyTable.c

index d328856ae5bcde1fdc5f4a785cc078bf65786747..1e79d18bf35c65fb3ae6568a86b6d67d2579f768 100644 (file)
@@ -832,9 +832,11 @@ ExecInsert(ModifyTableState *mtstate,
             *
             * We loop back here if we find a conflict below, either during
             * the pre-check, or when we re-check after inserting the tuple
-            * speculatively.
+            * speculatively.  Better allow interrupts in case some bug makes
+            * this an infinite loop.
             */
    vlock:
+           CHECK_FOR_INTERRUPTS();
            specConflict = false;
            if (!ExecCheckIndexConstraints(resultRelInfo, slot, estate,
                                           &conflictTid, arbiterIndexes))