diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 10bc3e0cae4..9f21c7c8dfe 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -384,6 +384,9 @@ WalSndErrorCleanup(void) if (xlogreader != NULL && xlogreader->seg.ws_file >= 0) wal_segment_close(xlogreader); + xlogreader = NULL; + logical_decoding_ctx = NULL; + if (MyReplicationSlot != NULL) ReplicationSlotRelease(); @@ -1032,6 +1035,9 @@ StartReplication(StartReplicationCmd *cmd) Assert(streamingDoneSending && streamingDoneReceiving); } + XLogReaderFree(xlogreader); + xlogreader = NULL; + if (cmd->slotname) ReplicationSlotRelease(); @@ -1601,6 +1607,8 @@ StartLogicalReplication(StartReplicationCmd *cmd) WalSndLoop(XLogSendLogical); FreeDecodingContext(logical_decoding_ctx); + logical_decoding_ctx = NULL; + xlogreader = NULL; ReplicationSlotRelease(); replication_active = false; @@ -2138,6 +2146,9 @@ exec_replication_command(const char *cmd_string) CHECK_FOR_INTERRUPTS(); + Assert(xlogreader == NULL); + Assert(logical_decoding_ctx == NULL); + /* * Prepare to parse and execute the command. * @@ -2295,7 +2306,6 @@ exec_replication_command(const char *cmd_string) /* dupe, but necessary per libpqrcv_endstreaming */ EndReplicationCommand(cmdtag); - Assert(xlogreader != NULL); break; }