diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 0ba2ad4414062ead6c20c50cd6d5c84ba97b6086..9207a48910b3c2a8752ebbcb52ea460f09ebd730 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -711,8 +711,11 @@ WalSndLoop(void)
 				XLogSend(output_message, &caughtup);
 				if (caughtup && !pq_is_send_pending())
 				{
-					ProcDiePending = true;
-					continue;	/* don't want to wait more */
+					/* Inform the standby that XLOG streaming is done */
+					pq_puttextmessage('C', "COPY 0");
+					pq_flush();
+
+					proc_exit(0);
 				}
 			}
 		}