Use correct connection for cancellation in frontend's parallel slots
authorMichael Paquier <[email protected]>
Sat, 27 Aug 2022 06:21:31 +0000 (15:21 +0900)
committerMichael Paquier <[email protected]>
Sat, 27 Aug 2022 06:21:31 +0000 (15:21 +0900)
While waiting for slots to become available in wait_on_slots() in
parallel_slot.c, the cancellation always relied on the first connection
in the set to do the job.  This could cause problems when this slot's
socket is gone as PQgetCancel() would return NULL in this case.  Rather
than always using the first connection, this changes the logic to use
the first valid connection for the cancellation.

Author: Ranier Vilela
Reviewed-by: Justin Pryzby
Discussion: https://postgr.es/m/CAEudQAokk1h_pUwGXsYS4oVOuf35s1O2o3TXGHpV8=AWikvgHA@mail.gmail.com
Backpatch-through: 14

src/fe_utils/parallel_slot.c

index 8bce8ca366377741aa3b58ade77fb7bd404f6f1e..2be2903c9c686c6bc201adf1d8f6ee16cfb533d3 100644 (file)
@@ -235,7 +235,7 @@ wait_on_slots(ParallelSlotArray *sa)
        if (cancelconn == NULL)
                return false;
 
-       SetCancelConn(sa->slots->connection);
+       SetCancelConn(cancelconn);
        i = select_loop(maxFd, &slotset);
        ResetCancelConn();