From 5f74d2b0ecbb06740bf5cefecb21a4e38136cfd2 Mon Sep 17 00:00:00 2001
From: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Date: Wed, 22 Jul 2026 08:58:34 +0200
Subject: Don't use pq_putmessage in socket comm function

Currently, socket_putmessage_noblock enlarges the output buffer to
avoid blocking and then calls pq_putmessage to store the message in the
buffer.

pq_putmessage is a macro redirecting to PqCommMethods->putmessage. This
is normally set to socket_putmessage, so socket_putmessage_noblock calls
socket_putmessage as desired.

If a different PqCommMethods is defined, any call to
socket_putmessage_noblock will then loop to the custom putmessage
implementation, breaking the interface layers.

This patch fixes the issue by directly using socket_putmessage in
socket_putmessage_noblock.
---
 src/backend/libpq/pqcomm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index ee9a39107e6..aaae7214f13 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -1537,7 +1537,7 @@ socket_putmessage_noblock(char msgtype, const char *s, size_t len)
 		PqSendBuffer = repalloc(PqSendBuffer, required);
 		PqSendBufferSize = required;
 	}
-	res = pq_putmessage(msgtype, s, len);
+	res = socket_putmessage(msgtype, s, len);
 	Assert(res == 0);			/* should not fail when the message fits in
 								 * buffer */
 }
-- 
2.55.0

