public inbox for [email protected]  
help / color / mirror / Atom feed
From: Markus Wanner <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Subject: Reset the output buffer after sending from WalSndWriteData
Date: Thu, 20 Feb 2025 21:49:46 +0100
Message-ID: <[email protected]> (raw)

Hi,

I recently stumbled over an issue with an unintentional re-transmission. 
While this clearly was our fault in the output plugin code, I think the 
walsender's exposed API could easily be hardened to prevent the bad 
consequence from this mistake.

Does anything speak against the attached one line patch?

Best Regards

Markus

Attachments:

  [text/x-patch] 0001-Reset-the-output-buffer-after-sending-from-WalSndWri.patch (1.1K, ../[email protected]/2-0001-Reset-the-output-buffer-after-sending-from-WalSndWri.patch)
  download | inline diff:
From 65dd24ed975cc513e4e0de5e175dff16b4b0f6d4 Mon Sep 17 00:00:00 2001
From: Markus Wanner <[email protected]>
Date: Thu, 20 Feb 2025 21:01:45 +0100
Subject: [PATCH] Reset the output buffer after sending from WalSndWriteData

While not strictly necessary, clearing the buffer right away after
sending prevents an accidential re-delivery in case WalSndWriteData
is called again.
---
 src/backend/replication/walsender.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 446d10c1a7d..96884ce152f 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1563,6 +1563,9 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
 	/* output previously gathered data in a CopyData packet */
 	pq_putmessage_noblock('d', ctx->out->data, ctx->out->len);
 
+	/* reset the output buffer to prevent re-sending */
+	resetStringInfo(ctx->out);
+
 	CHECK_FOR_INTERRUPTS();
 
 	/* Try to flush pending output to the client */
-- 
2.39.5



view thread (2+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Reset the output buffer after sending from WalSndWriteData
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox