[PATCH] Clear walsender reader pointers after cleanup

From: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>
Subject: [PATCH] Clear walsender reader pointers after cleanup
Date: 2026-10-11 09:54:27
Message-ID: CAJTYsWW+hdmmVt_A4hvGv2_5RWK8-kaOf5ncT65=5i_hyD=BHg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

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.

I tried sending CopyDone, draining the replies, then TIMELINE_HISTORY 99.
With --enable-cassert, I get close(0x7F7F7F7F). The connection stays up,
but the attached patch stops that invalid close.

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?

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

Regards,
Ayush

Attachment Content-Type Size
v1-0001-Clear-walsender-reader-pointers-after-cleanup.patch application/octet-stream 2.0 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Richard Guo 2026-10-11 12:41:03 Re: Wrong results from an antijoin
Previous Message Dilip Kumar 2026-10-11 09:36:41 Re: Proposal: Conflict log history table for Logical Replication