On 02/12/2026 14:29, Greg Burd wrote:
On Tue, Dec 1, 2026 at 12:39 PM Robert Haas <[email protected]> wrote:
It thinks the patch regresses behavior in the case
where a parallel worker and an apply worker fail at the same time,
because ParallelMessagePending will get cleared but only the parallel
worker's message will get handled, since it throws an error. If the
leader then catches that error, the process continues with a pending
message but no flag set that will cause us to read it.

I confirmed your suspicion with an injection point that makes the first
reader throw once, inside a PL/pgSQL block that catches the error.

The attached v17 wraps the three readers in PG_TRY().  0001's PG_CATCH()
sets the flag again, 0008's raises INTERRUPT_PARALLEL_MESSAGE again, and
both rethrow.  With that change, the same probe runs the handler a
second time, which reads the queues the error skipped.
Right, that's the straightforward bandaid that Claude suggests.

Stepping back, the problem is that if processing the message throws an error, any other messages that might be pending won't be processed. That seems OK on master but it feels a bit shaky. If ProccessParallelMessages() throws an ERROR, the rest of the messages won't be processed, but that's OK, because all the workers are part of the same parallel context, and they will be shut down on error cleanup. For parallel apply, ProcessParallelApplyMessage() assumes that throwing an error will terminate the whole leader process, so it's also OK to not process any remaining parallel apply messages.

There's one corner case in master already in that scenario (i.e. you have parallel query workers and parallel apply workers and a PL/pgSQL block that catches an error): If you receive an error from a parallel apply worker, ProcessParallelApplyMessage() throws the ERROR:

ERROR:  logical replication parallel apply worker exited due to error
DETAIL: The leader apply worker will now exit and terminate any other parallel apply workers.

However, if that happens in the PL/pgSQL block, the exception handler will catch that ERROR, abort just the subtransaction, and continue running. I wonder if that should be FATAL? Or if we should do some other more explicit cleanup, instead of relying on process exit?

- Heikki



Reply via email to