Skip to content

Commit 03f06ff

Browse files
committed
Fix some more bugs in signal handlers and process shutdown logic.
WalSndKill was doing things exactly backwards: it should first clear MyWalSnd (to stop signal handlers from touching MyWalSnd->latch), then disown the latch, and only then mark the WalSnd struct unused by clearing its pid field. Also, WalRcvSigUsr1Handler and worker_spi_sighup failed to preserve errno, which is surely a requirement for any signal handler. Per discussion of recent buildfarm failures. Back-patch as far as the relevant code exists.
1 parent e5c22c1 commit 03f06ff

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/backend/replication/walsender.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -920,17 +920,23 @@ InitWalSnd(void)
920920
static void
921921
WalSndKill(int code, Datum arg)
922922
{
923-
Assert(MyWalSnd != NULL);
923+
WalSnd *walsnd = MyWalSnd;
924+
925+
Assert(walsnd != NULL);
926+
927+
/*
928+
* Clear MyWalSnd first; then disown the latch. This is so that signal
929+
* handlers won't try to touch the latch after it's no longer ours.
930+
*/
931+
MyWalSnd = NULL;
932+
933+
DisownLatch(&walsnd->latch);
924934

925935
/*
926936
* Mark WalSnd struct no longer in use. Assume that no lock is required
927937
* for this.
928938
*/
929-
MyWalSnd->pid = 0;
930-
DisownLatch(&MyWalSnd->latch);
931-
932-
/* WalSnd struct isn't mine anymore */
933-
MyWalSnd = NULL;
939+
walsnd->pid = 0;
934940
}
935941

936942
/*

0 commit comments

Comments
 (0)