Skip to content

Commit 6479df1

Browse files
committed
In Windows pg_dump, ensure idle workers will shut down during error exit.
The Windows coding of ShutdownWorkersHard() thought that setting termEvent was sufficient to make workers exit after an error. But that only helps if a worker is busy and passes through checkAborting(). An idle worker will just sit, resulting in pg_dump failing to exit until the user gives up and hits control-C. We should close the write end of the command pipe so that idle workers will see socket EOF and exit, as the Unix coding was already doing. Back-patch to 9.3 where parallel pg_dump was introduced. Kyotaro Horiguchi
1 parent b2355a2 commit 6479df1

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/bin/pg_dump/parallel.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,28 +299,26 @@ checkAborting(ArchiveHandle *AH)
299299
}
300300

301301
/*
302-
* Shut down any remaining workers, this has an implicit do_wait == true.
303-
*
304-
* The fastest way we can make the workers terminate gracefully is when
305-
* they are listening for new commands and we just tell them to terminate.
302+
* Shut down any remaining workers, waiting for them to finish.
306303
*/
307304
static void
308305
ShutdownWorkersHard(ParallelState *pstate)
309306
{
310-
#ifndef WIN32
311307
int i;
312308

313309
/*
314-
* Close our write end of the sockets so that the workers know they can
315-
* exit.
310+
* Close our write end of the sockets so that any workers waiting for
311+
* commands know they can exit.
316312
*/
317313
for (i = 0; i < pstate->numWorkers; i++)
318314
closesocket(pstate->parallelSlot[i].pipeWrite);
319315

316+
#ifndef WIN32
317+
/* On non-Windows, send SIGTERM to abort commands-in-progress. */
320318
for (i = 0; i < pstate->numWorkers; i++)
321319
kill(pstate->parallelSlot[i].pid, SIGTERM);
322320
#else
323-
/* The workers monitor this event via checkAborting(). */
321+
/* Non-idle workers monitor this event via checkAborting(). */
324322
SetEvent(termEvent);
325323
#endif
326324

0 commit comments

Comments
 (0)