pgsql: Avoid blocking indefinitely while finishing walsender shutdown - Mailing list pgsql-committers

From Fujii Masao
Subject pgsql: Avoid blocking indefinitely while finishing walsender shutdown
Date
Msg-id E1wIeKp-003XfX-1I@gemulon.postgresql.org
Whole thread
List 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@anarazel.de>
Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.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(-)


pgsql-committers by date:

Previous
From: Richard Guo
Date:
Subject: pgsql: Fix HAVING-to-WHERE pushdown with nondeterministic collations
Next
From: Michael Paquier
Date:
Subject: pgsql: doc: Mention validation attempt during ALTER INDEX .. ATTACH PAR