@@ -118,7 +118,7 @@ static void DisableWalRcvImmediateExit(void);
118118static void WalRcvDie (int code ,Datum arg );
119119static void XLogWalRcvProcessMsg (unsignedchar type ,char * buf ,Size len );
120120static void XLogWalRcvWrite (char * buf ,Size nbytes ,XLogRecPtr recptr );
121- static void XLogWalRcvFlush (void );
121+ static void XLogWalRcvFlush (bool dying );
122122static 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}
324324else
325325{
@@ -342,7 +342,7 @@ WalRcvDie(int code, Datum arg)
342342volatile WalRcvData * walrcv = WalRcv ;
343343
344344/* Ensure that all WAL records received are flushed to disk */
345- XLogWalRcvFlush ();
345+ XLogWalRcvFlush (true );
346346
347347SpinLockAcquire (& walrcv -> mutex );
348348Assert (walrcv -> walRcvState == WALRCV_RUNNING ||
@@ -461,7 +461,7 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr)
461461 */
462462if (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+ */
535540static void
536- XLogWalRcvFlush (void )
541+ XLogWalRcvFlush (bool dying )
537542{
538543if (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