Skip to content

Commit 81b116d

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 fad4437 commit 81b116d

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
@@ -950,17 +950,23 @@ InitWalSnd(void)
950950
static void
951951
WalSndKill(int code, Datum arg)
952952
{
953-
Assert(MyWalSnd != NULL);
953+
WalSnd *walsnd = MyWalSnd;
954+
955+
Assert(walsnd != NULL);
956+
957+
/*
958+
* Clear MyWalSnd first; then disown the latch. This is so that signal
959+
* handlers won't try to touch the latch after it's no longer ours.
960+
*/
961+
MyWalSnd = NULL;
962+
963+
DisownLatch(&walsnd->latch);
954964

955965
/*
956966
* Mark WalSnd struct no longer in use. Assume that no lock is required
957967
* for this.
958968
*/
959-
MyWalSnd->pid = 0;
960-
DisownLatch(&MyWalSnd->latch);
961-
962-
/* WalSnd struct isn't mine anymore */
963-
MyWalSnd = NULL;
969+
walsnd->pid = 0;
964970
}
965971

966972
/*

0 commit comments

Comments
 (0)