Don't use pq_putmessage in socket comm function

Started by Anthonin Bonnefoy4 days ago5 messageshackers
Jump to latest
#1Anthonin Bonnefoy
anthonin.bonnefoy@datadoghq.com

Hi,

Currently, socket_putmessage_noblock enlarges the output buffer 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.

However, if a custom PqCommMethods is defined, any call to
socket_putmessage_noblock will then loop to the custom putmessage.

This patch fixes the issue by directly using socket_putmessage in
socket_putmessage_noblock.

Regards,
Anthonin Bonnefoy

Attachments:

v1-0001-Don-t-use-pq_putmessage-in-socket-comm-function.patchapplication/octet-stream; name=v1-0001-Don-t-use-pq_putmessage-in-socket-comm-function.patchDownload+1-2
#2Michael Paquier
michael@paquier.xyz
In reply to: Anthonin Bonnefoy (#1)
Re: Don't use pq_putmessage in socket comm function

On Wed, Jul 22, 2026 at 10:16:53AM +0200, Anthonin Bonnefoy wrote:

However, if a custom PqCommMethods is defined, any call to
socket_putmessage_noblock will then loop to the custom putmessage.

This patch fixes the issue by directly using socket_putmessage in
socket_putmessage_noblock.

Yes, that's strange. It seems like a mistake going down to 9.5, as of
2bd9e412f92b where socket_putmessage_noblock() has been introduced,
leaving the pq_putmessage() around.

Thoughts or opinions?
--
Michael

#3Fujii Masao
masao.fujii@gmail.com
In reply to: Michael Paquier (#2)
Re: Don't use pq_putmessage in socket comm function

On Wed, Jul 22, 2026 at 5:30 PM Michael Paquier <michael@paquier.xyz> wrote:

Yes, that's strange. It seems like a mistake going down to 9.5, as of
2bd9e412f92b where socket_putmessage_noblock() has been introduced,
leaving the pq_putmessage() around.

Thoughts or opinions?

Agreed. The proposed change looks correct to me.

Regards,

--
Fujii Masao

#4Michael Paquier
michael@paquier.xyz
In reply to: Fujii Masao (#3)
Re: Don't use pq_putmessage in socket comm function

On Wed, Jul 22, 2026 at 06:15:15PM +0900, Fujii Masao wrote:

Agreed. The proposed change looks correct to me.

Done this one, but only on HEAD as the existing code is not broken,
either. That's debatable.
--
Michael

#5Anthonin Bonnefoy
anthonin.bonnefoy@datadoghq.com
In reply to: Michael Paquier (#4)
Re: Don't use pq_putmessage in socket comm function

On Thu, Jul 23, 2026 at 10:06 AM Michael Paquier <michael@paquier.xyz> wrote:

Done this one, but only on HEAD as the existing code is not broken,
either. That's debatable.

Thanks! I agree that this isn't an issue with the current PqCommMethods code.

I'm currently experimenting using a custom PQcommMethods layer to
compress messages, which then use PqCommSocketMethods to forward the
compressed payloads. That's how I've triggered the issue with the
socket_putmessage_noblock calling back compression's putmessage.

Without a similar setup with multiple PQcommMethods layers,
socket_putmessage_noblock using pq_putmessage shouldn't be an issue.

Regards,
Anthonin Bonnefoy