Re: [PATCH] Clear walsender reader pointers after cleanup

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Clear walsender reader pointers after cleanup
Date: 2026-10-12 23:05:02
Message-ID: as1nnn7wpF8Jq93W@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Oct 11, 2026 at 02:54:27AM -0700, Ayush Tiwari wrote:
> FreeDecodingContext() frees the reader when logical streaming ends, but
> xlogreader is left pointing to it. If the next command on that connection
> fails, WalSndErrorCleanup() still follows that pointer.

You have been able to reach that without patching the backend and only
sending protocol-level messages while maintaining a replication
connection with a database, haven't you? This would be enough to
warrant a backpatch to keep the state of the live connection clean.

> The patch clears the pointers after streaming and error cleanup. For
> physical streaming, I've also freed the reader before returning. Is there
> a reason to leave that part to cmd_context reset instead?

StartReplication() is complicated enough that I'd be OK with just
adding an extra XLogReaderFree() there. It makes plainly clear that
once we are done with the replication bytes, the xlogreader state
allocated at the beginning of StartReplication() stored statically is
not something we should rely on anymore.

> I've adjusted the assertion too, since it runs after the streaming
> function returns. At that point the pointers are now NULL.

I don't feel strongly about these additions though. What do they
actually buy?
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-10-12 23:33:33 Re: [Patch] New pg_stat_tablespace view
Previous Message Sho Ito 2026-10-12 22:31:52 Re: PG19: flat-copied RelOptInfos share extension_state with the original rel