*/
/*
- * Check for replication timeout if it's enabled and we need to
- * wait for the socket to be writable to flush pending WAL in
- * output buffer.
+ * Check for replication timeout if it's enabled and we need
+ * to wait until the socket has become writable to flush
+ * pending WAL in output buffer or until the Ack message
+ * from the standby has become available.
*/
- check_timeout = replication_timeout > 0 && pending;
- if (check_timeout)
+ if (replication_timeout > 0 &&
+ (pending ||
+ (rplMode != REPLICATION_MODE_ASYNC &&
+ XLByteLT(ackdPtr, sentPtr))))
+ {
sleeptime = replication_timeout;
+ check_timeout = true;
+ }
else
+ {
sleeptime = WalSndDelay;
+ check_timeout = false;
+ }
/* Sleep */
res = WaitLatchOrSocket(&MyWalSnd->latch, MyProcPort->sock,