Skip to content

Commit 3a08736

Browse files
committed
WAL receiver shouldn't try to send a reply when dying.
Per report from, and discussion with, Fujii Masao.
1 parent 6e02755 commit 3a08736

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/backend/replication/walreceiver.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static void DisableWalRcvImmediateExit(void);
118118
static void WalRcvDie(int code, Datum arg);
119119
static void XLogWalRcvProcessMsg(unsigned char type, char *buf, Size len);
120120
static void XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr);
121-
static void XLogWalRcvFlush(void);
121+
static void XLogWalRcvFlush(bool dying);
122122
static void XLogWalRcvSendReply(void);
123123

124124
/* Signal handlers */
@@ -319,7 +319,7 @@ WalReceiverMain(void)
319319
* If we've written some records, flush them to disk and let the
320320
* startup process know about them.
321321
*/
322-
XLogWalRcvFlush();
322+
XLogWalRcvFlush(false);
323323
}
324324
else
325325
{
@@ -342,7 +342,7 @@ WalRcvDie(int code, Datum arg)
342342
volatile WalRcvData *walrcv = WalRcv;
343343

344344
/* Ensure that all WAL records received are flushed to disk */
345-
XLogWalRcvFlush();
345+
XLogWalRcvFlush(true);
346346

347347
SpinLockAcquire(&walrcv->mutex);
348348
Assert(walrcv->walRcvState == WALRCV_RUNNING ||
@@ -461,7 +461,7 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr)
461461
*/
462462
if (recvFile >= 0)
463463
{
464-
XLogWalRcvFlush();
464+
XLogWalRcvFlush(false);
465465

466466
/*
467467
* XLOG segment files will be re-read by recovery in startup
@@ -531,9 +531,14 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr)
531531
}
532532
}
533533

534-
/* Flush the log to disk */
534+
/*
535+
* Flush the log to disk.
536+
*
537+
* If we're in the midst of dying, it's unwise to do anything that might throw
538+
* an error, so we skip sending a reply in that case.
539+
*/
535540
static void
536-
XLogWalRcvFlush(void)
541+
XLogWalRcvFlush(bool dying)
537542
{
538543
if (XLByteLT(LogstreamResult.Flush, LogstreamResult.Write))
539544
{
@@ -565,7 +570,8 @@ XLogWalRcvFlush(void)
565570
}
566571

567572
/* Also let the master know that we made some progress */
568-
XLogWalRcvSendReply();
573+
if (!dying)
574+
XLogWalRcvSendReply();
569575
}
570576
}
571577

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy