v8.1-0002-fe_utils-Simplify-cancel-logic-in-wait_on_slots.patch
text/x-patch
Filename: v8.1-0002-fe_utils-Simplify-cancel-logic-in-wait_on_slots.patch
Type: text/x-patch
Part: 1
Patch
Format: format-patch
Series: patch v8-0002
Subject: fe_utils: Simplify cancel logic in wait_on_slots
| File | + | − |
|---|---|---|
| src/fe_utils/parallel_slot.c | 6 | 10 |
From 4aac255e262685d14045a3fb33c7ca0ab881628e Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Tue, 7 Apr 2026 19:54:13 +0200
Subject: [PATCH v8.1 2/4] fe_utils: Simplify cancel logic in wait_on_slots
This removes the SetCancelConn call in wait_on_slots. This call was
confusing because it was only called for a single connection of all the
connections that the select_loop would wait on. Turns out that it can be
be made completely redundant by moving the check for CancelRequested
before the check for EINTR.
---
src/fe_utils/parallel_slot.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/src/fe_utils/parallel_slot.c b/src/fe_utils/parallel_slot.c
index fb9e6cc4ec1..94d13cc499a 100644
--- a/src/fe_utils/parallel_slot.c
+++ b/src/fe_utils/parallel_slot.c
@@ -103,6 +103,9 @@ select_loop(int maxFd, fd_set *workerset)
*workerset = saveSet;
i = select(maxFd + 1, workerset, NULL, NULL, tvp);
+ if (CancelRequested)
+ return -1;
+
#ifdef WIN32
if (i == SOCKET_ERROR)
{
@@ -115,7 +118,7 @@ select_loop(int maxFd, fd_set *workerset)
if (i < 0 && errno == EINTR)
continue; /* ignore this */
- if (i < 0 || CancelRequested)
+ if (i < 0)
return -1; /* but not this */
if (i == 0)
continue; /* timeout (Win32 only) */
@@ -197,8 +200,7 @@ wait_on_slots(ParallelSlotArray *sa)
{
int i;
fd_set slotset;
- int maxFd = 0;
- PGconn *cancelconn = NULL;
+ int maxFd = -1;
/* We must reconstruct the fd_set for each call to select_loop */
FD_ZERO(&slotset);
@@ -219,10 +221,6 @@ wait_on_slots(ParallelSlotArray *sa)
if (sock < 0)
continue;
- /* Keep track of the first valid connection we see. */
- if (cancelconn == NULL)
- cancelconn = sa->slots[i].connection;
-
FD_SET(sock, &slotset);
if (sock > maxFd)
maxFd = sock;
@@ -232,12 +230,10 @@ wait_on_slots(ParallelSlotArray *sa)
* If we get this far with no valid connections, processing cannot
* continue.
*/
- if (cancelconn == NULL)
+ if (maxFd < 0)
return false;
- SetCancelConn(cancelconn);
i = select_loop(maxFd, &slotset);
- ResetCancelConn();
/* failure? */
if (i < 0)
--
2.47.3