@@ -1428,10 +1428,8 @@ WalSndWaitForWal(XLogRecPtr loc)
1428
1428
/*
1429
1429
* We only send regular messages to the client for full decoded
1430
1430
* transactions, but a synchronous replication and walsender shutdown
1431
- * possibly are waiting for a later location. So, before sleeping, we
1432
- * send a ping containing the flush location. If the receiver is
1433
- * otherwise idle, this keepalive will trigger a reply. Processing the
1434
- * reply will update these MyWalSnd locations.
1431
+ * possibly are waiting for a later location. So we send pings
1432
+ * containing the flush location every now and then.
1435
1433
*/
1436
1434
if (MyWalSnd -> flush < sentPtr &&
1437
1435
MyWalSnd -> write < sentPtr &&
@@ -2316,23 +2314,30 @@ WalSndLoop(WalSndSendDataCallback send_data)
2316
2314
WalSndKeepaliveIfNecessary ();
2317
2315
2318
2316
/*
2319
- * Block if we have unsent data. Let WalSndWaitForWal() handle any
2320
- * other blocking; idle receivers need its additional actions.
2317
+ * We don't block if not caught up, unless there is unsent data
2318
+ * pending in which case we'd better block until the socket is
2319
+ * write-ready. This test is only needed for the case where the
2320
+ * send_data callback handled a subset of the available data but then
2321
+ * pq_flush_if_writable flushed it all --- we should immediately try
2322
+ * to send more.
2321
2323
*/
2322
- if (pq_is_send_pending ())
2324
+ if (( WalSndCaughtUp && ! streamingDoneSending ) || pq_is_send_pending ())
2323
2325
{
2324
2326
long sleeptime ;
2325
2327
int wakeEvents ;
2326
2328
2327
2329
wakeEvents = WL_LATCH_SET | WL_EXIT_ON_PM_DEATH | WL_TIMEOUT |
2328
- WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE ;
2330
+ WL_SOCKET_READABLE ;
2329
2331
2330
2332
/*
2331
2333
* Use fresh timestamp, not last_processing, to reduce the chance
2332
2334
* of reaching wal_sender_timeout before sending a keepalive.
2333
2335
*/
2334
2336
sleeptime = WalSndComputeSleeptime (GetCurrentTimestamp ());
2335
2337
2338
+ if (pq_is_send_pending ())
2339
+ wakeEvents |= WL_SOCKET_WRITEABLE ;
2340
+
2336
2341
/* Sleep until something happens or we time out */
2337
2342
(void ) WaitLatchOrSocket (MyLatch , wakeEvents ,
2338
2343
MyProcPort -> sock , sleeptime ,
0 commit comments