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 <[email protected]>
Author: Fujii Masao <[email protected]>
Reviewed-by: Chao Li <[email protected]>
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(-)

Reply via email to