| From: | Zhijie Hou <houzhijie22(at)gmail(dot)com> |
|---|---|
| To: | Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> |
| Cc: | "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Fix race between copying and dropping a replication slot |
| Date: | 2026-12-01 12:47:52 |
| Message-ID: | 67fb502f-966d-46e6-bc60-de4727faad8c@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On Tue, Dec 1, 2026 at 02:44 AM Masahiko Sawada wrote:
>
> On Thu, Nov 26, 2026 at 6:39 AM Zhijie Hou <houzhijie22(at)gmail(dot)com> wrote:
> > Attached a patch to fix this by checking second_slot_contents.in_use
> > and ensuring MyReplicationSlot did not reuse src in the second
> > phase. The code fix applies back to PG 15.
>
> I've reviewed the patch and have some comments:
>
> - if (copy_restart_lsn < src_restart_lsn ||
> + if (!second_slot_contents.in_use ||
> + src == MyReplicationSlot ||
> + copy_restart_lsn < src_restart_lsn ||
>
> I think the new in_use check is right, but IIUC the second check (src
> == MyReplicationSlot) is needed only when the source and the
> destination have the same name. If the names differ and the
> destination reuses the source's entry, the existing name check catches
> it. Copying a slot to itself doesn't make sense to me, so I think we
> should not allow such an operation at the beginning of this function
> instead.
>
> ---
> It's not a part of your patch but the following comment is not true
> for physical slots:
>
> * Since erroring out will release and drop the destination slot we
> * don't need to release it here.
> */
>
> While it's not a new issue that a physical slot remains when erroring
> out at the creation, I think we can update the comment as well.
Thanks for the comments! Both comments have been addressed in v2 patch.
--
Best Regards,
Zhijie Hou
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Fix-race-between-copying-and-dropping-a-replicati.patch | text/plain | 11.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nazir Bilal Yavuz | 2026-12-01 13:30:55 | Report standby replay progress during archive recovery |
| Previous Message | Rui Zhao | 2026-12-01 12:46:21 | Re: improvements / reworks for FDW insert batching |