pgsql: Avoid blocking indefinitely while finishing walsender shutdown

From: Fujii Masao <fujii(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid blocking indefinitely while finishing walsender shutdown
Date: 2026-05-01 03:14:36
Message-ID: E1wIeKp-003XfX-1I@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid blocking indefinitely while finishing walsender shutdown

When walsender finishes streaming during shutdown, it sends a
CommandComplete message to tell the receiver that WAL streaming is done.
Previously, that path used EndCommand() followed by pq_flush().

Those functions can block indefinitely waiting for the socket to become
writeable. As a result, even when wal_sender_shutdown_timeout is set,
walsender could remain stuck while sending the final completion message,
and the shutdown timeout would not be enforced.

Fix this by introducing EndCommandExtended(), which allows
CommandComplete to be queued with pq_putmessage_noblock(), and by
using the walsender nonblocking flush path instead of pq_flush(), so
the shutdown timeout continues to be checked while pending output is
flushed.

Per CI testing on FreeBSD.

Reported-by: Andres Freund <andres(at)anarazel(dot)de>
Author: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Discussion: https://postgr.es/m/vwlugmsogfn36jhm56zwrgd7m6xe6ircltvfh3kzt6kldvbtht@f45dgow5uhnx

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/c0b24b32b0d3776435923d55396cc43fc657ecc5

Modified Files
--------------
src/backend/replication/walsender.c | 66 +++++++++++++++++++++++++++++++++----
src/backend/tcop/dest.c | 15 +++++++--
src/include/tcop/dest.h | 2 ++
3 files changed, 75 insertions(+), 8 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2026-05-01 04:11:12 pgsql: doc: Mention validation attempt during ALTER INDEX .. ATTACH PAR
Previous Message Richard Guo 2026-05-01 02:17:38 pgsql: Fix HAVING-to-WHERE pushdown with nondeterministic collations