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

Attachment: signature.asc
Description: PGP signature

Reply via email to