From e3d7ea0c60ca0febdacfa0a3681183be942384fa Mon Sep 17 00:00:00 2001 From: Shihao Date: Tue, 29 Sep 2026 21:35:39 -0600 Subject: [PATCH] Detach the parallel DSM segment after the workers have exited DestroyParallelContext() detached the segment before the workers exited. A worker still starting up failed to attach and logged an error. --- src/backend/access/transam/parallel.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index 4004484e802..d43a09ad800 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -992,6 +992,21 @@ DestroyParallelContext(ParallelContext *pcxt) } } + /* + * Wait for the workers to exit before detaching the segment. A worker + * that is still starting up may not have attached to the segment, or to + * the objects in it, and would fail if they were already gone. The error + * queues are detached above, so a worker blocked on sending an error + * cannot make us wait forever. + * + * We can't finish transaction commit or abort until all of the workers + * have exited. This means, in particular, that we can't respond to + * interrupts at this stage. + */ + HOLD_INTERRUPTS(); + WaitForParallelWorkersToExit(pcxt); + RESUME_INTERRUPTS(); + /* * If we have allocated a shared memory segment, detach it. This will * implicitly detach the error queues, and any other shared memory queues, @@ -1013,15 +1028,6 @@ DestroyParallelContext(ParallelContext *pcxt) pcxt->private_memory = NULL; } - /* - * We can't finish transaction commit or abort until all of the workers - * have exited. This means, in particular, that we can't respond to - * interrupts at this stage. - */ - HOLD_INTERRUPTS(); - WaitForParallelWorkersToExit(pcxt); - RESUME_INTERRUPTS(); - /* Free the worker array itself. */ if (pcxt->worker != NULL) { -- 2.37.1 (Apple Git-137.1)