pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: feichanghong <feichanghong@qq.com>
Cc: pgsql-bugs <pgsql-bugs@lists.postgresql.org>
Cc: andres <andres@anarazel.de>
Cc: sawada.mshk <sawada.mshk@gmail.com>
Cc: horikyota.ntt <horikyota.ntt@gmail.com>
Subject: Re: ReplicationSlotRelease may set the statusFlags of other processes in PG14
Date: Tue, 19 Mar 2024 12:57:51 +0900
Message-ID: <ZfkNP1OdgBSPPTsR@paquier.xyz> (raw)
In-Reply-To: <tencent_CA7420C82971BC4B64F0748A7D2898A4720A@qq.com>
References: <tencent_CA7420C82971BC4B64F0748A7D2898A4720A@qq.com>

On Sat, Mar 16, 2024 at 10:29:03PM +0800, feichanghong wrote:
> A process utilizing replication slots (usually walsender) calls callback
> functions in the order of RemoveProcFromArray->ProcKill upon abnormal exit.
> Within RemoveProcFromArray, MyProc is already removed from the ProcArray.
> ProcKill then attempts to set ProcGlobal->statusFlags[MyProc->pgxactoff] again
> via ReplicationSlotRelease. By this time, the flag may already be assigned to
> another process.

Oops.

> To replicate the issue, execute the following steps:
> 1. Apply the attached v1-0000-v14-invalidate-pgxactoff-after-remove-pgproc.patch,
> where pgxactoff is set to an invalid value in ProcArrayRemove, and some
> checks are added.
> 2. Use the SQL below to terminate the walsender process.
> ```
> select pg_terminate_backend(pid) from pg_stat_activity where backend_type = 'walsender';
> ```
> # Fix
> 
> To fix the issue, I have provided some patches in the attachment:
> 1. Backpatching 2f6501f into the PG14 version will fix the problem.
> 2. In PG14-head, ProcArrayRemove needs to reset pgxactoff, and some assert
> checks should be done when setting ProcGlobal->statusFlags.

Yeah, that's something that we had better fix in all stable branches.
The asserts would offer some protection moving on, but I would take
the safer move of only adding a protection like what you are
suggestion on HEAD and not in stable branches, just in case we're
missing something around them.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (3+ messages)  latest in thread

Message-ID: <ZfkNP1OdgBSPPTsR@paquier.xyz>
Permalink:  ../ZfkNP1OdgBSPPTsR@paquier.xyz/
Also on:    postgresql.org/message-id/ZfkNP1OdgBSPPTsR@paquier.xyz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: michael@paquier.xyz, feichanghong@qq.com, pgsql-bugs@lists.postgresql.org, andres@anarazel.de, sawada.mshk@gmail.com, horikyota.ntt@gmail.com
  Subject: Re: ReplicationSlotRelease may set the statusFlags of other processes in PG14
  In-Reply-To: <ZfkNP1OdgBSPPTsR@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox