Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wUkKE-001PmF-1M for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jun 2026 12:03:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wUkKD-001Jdr-0j for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jun 2026 12:03:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wUkKC-001Jdi-2o for pgsql-hackers@lists.postgresql.org; Wed, 03 Jun 2026 12:03:56 +0000 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wUkKA-000000012u1-3GCs for pgsql-hackers@lists.postgresql.org; Wed, 03 Jun 2026 12:03:56 +0000 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-4865b9e16d4so317528b6e.1 for ; Wed, 03 Jun 2026 05:03:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780488232; cv=none; d=google.com; s=arc-20240605; b=esvSzUl6twN8ZjBS4H675em0dxPMdX7EDuh3Yxe36W55sZkH7f0tPnio/Sha+DuCI8 9qJLQD8KcBk1/jkgYW8sOVKL0jsdUgqy2G16eaoF79DmbK1IQ4yYahJ437QoBdGKMChd a420arWChMQiRTCRT5+FHZ1KbI0W8+pJQalL72nDb9xAm8VqIiu45ZahNCYbrLDM6Nrf c4Buo4ovxNG7VwEKX75KyHgQAYZhXoQYjRbQ2x/zodZ0EIQiKX3YGsMDwzcoWBTJCCQT PO0OR50OE4t8bXnIuIuMCeJOFhFObY6wFAExCcT/FQ10LSFv5lr/J3IcJArXIcqoCW0i 7lOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=9Gf0cXX1e3f4+tXsbXgKVS0EBvGp97q4nAIaGeBw0M8=; fh=urNdFhG8iN2lXlXFJUqgO9u+2tDi2rRk6JdW6b2gNbo=; b=Rcr5trwgtlDkvQIXn0cp9/zyGtmiZaEwrXRcr5geeDcuCRCS3XGWqnuKbkzV535hrH Hh1kgtTXgHwaFLlwj8Msar2c3/noR7t+6jdzDlBA/71dQ4euKDOHl5oonw4QZHrS/Y12 uO+YeB9Qg85LN3LvZoyBN8hx/iZINy4nzYUD8B1TgpVYtE4Mq3P0U+E/vay+OoWtYcvL +vRGHkLCtQaGwHlp3IUxiK2/IRt3Y39Ft2/BHnX3vSuYFvZVb/pddwXJnvIGCwD+0ZsC D7lBU7Eh+pwtavhVbbqVs+2mz8DVYuaM/WOyu+IT2lEWvW354TuMJviOw9t+M24jfM8w ZTkA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780488232; x=1781093032; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9Gf0cXX1e3f4+tXsbXgKVS0EBvGp97q4nAIaGeBw0M8=; b=Iw7ElyTC/Fx9YfWUNdqgXdJIdt3dzXsI/qE14qR8rJsHiRB7grFJO36AK7A20xqXVf Fi7yiZ+RUFYpqMhIba14kLBsvzynne52yboCPseCaCs7jkLG3s3TgxEkzfsrfy57zFXF cGDF0wEg7jxWNjJGmGHQ7doJIcgDDBcoGsrjyDuWC0YNgChdS+reMR3P0lMc7fQcAScm o4pf0mm8fPfyjy+p9J0VpV+Nn4sI6Mmq7tqizvTEdVJ2/ausMB10X0Db98qemxepC2NX FaEBJeSvnysgFlOFKJlwV6w67zyvifjr0gqc70XFgygqivx+R9jfZ8L7h++luC3YNY5z w1Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780488232; x=1781093032; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=9Gf0cXX1e3f4+tXsbXgKVS0EBvGp97q4nAIaGeBw0M8=; b=U2MBEevlM2dJHXreDRBUHM+CYxzE0Lq6UBrDh+2jWFIUE2l7fbcIgxzAq44tZJURVl dQ2fCCpzCKdhoRdKNCEQ4+i+HfK8FKsdweScrwkuq57iKiD9WKJOFTS5iSCoFU4xKWmC 1l2bVtImNGiQNR8TWKix8dDJnZ3AsZlAuv7LPT/2fwSqu/NCMsn/Nv1Ct82EoXCv6GBV axPxhJvecnev9klrwRMRjLc0qpaCa2ra2rZASyX081qvhbC1cXoAStcmiOKMlW6AfRjK VNToeoKm3Wd5MDk7l9hUSULXJXJN7GABkJ0VMkH6iD67t1k+TZYxqjQ3Rf3fz94K64I/ jpPg== X-Forwarded-Encrypted: i=1; AFNElJ+7Ca4SMf/PrgYcNTxd7B7/qeFTfyFZntBkb82fdIJBpjJ5eov1b4pm0RWJwuQVRBU0BiVTUa5SoOPlIh/I@lists.postgresql.org X-Gm-Message-State: AOJu0YzCoWsQUiGlnJSdCTKb52HflI7CXeIhvGvcHTamBsIo9Ou7Y4Z8 t/wvTVMvd55gT5wpdhKA5vTZIspAIpwZ1wJzt/0DcjtVMkAFPvZcELQkEslchhkg8eqQOv/nmo6 q9DnaSeHmlUhq/ok1/kK1QXnT9w5QaE3u/G5wH0E= X-Gm-Gg: Acq92OFiULKxofiWHO1Fih7b2pul/S5jTdfRA/phfTUuCG0ExmGcgDbd1FpO6g88lgj mHPhxJZKm/xD+zdwl/duE1gHmjJ85BCx+zXvNtjeYe3k6wQ7TazdazwCFCuyvH3Bx79xeu/kvaL w2FCkJN2iDcwP0oSaZJo+Mh8uPNoHVkxMbxuubODVXdovolzTx0giKTbclRBDpdKtIw39gWjgj0 yHqKr1apKFFpvB9BqqUAQHq9pdSOlxa8ep9cCl456zGNWf5S+cD0qiqbzbMqT6XIOu0uMlaaq8g GeJUBxafuHnB1XL0P/WydYbuUMbLFrppX8H4+h180a1N0gGMxSg= X-Received: by 2002:a05:6808:509e:b0:47b:d505:d84 with SMTP id 5614622812f47-4865aceec38mr1683720b6e.33.1780488232251; Wed, 03 Jun 2026 05:03:52 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Fujii Masao Date: Wed, 3 Jun 2026 21:03:39 +0900 X-Gm-Features: AVHnY4Lvr-8JN4L6Ylbt_fGVgdo9piDxar6VPfMmzbi7MhA-4CPqmvyxzxbrzzA Message-ID: Subject: Re: Fix race in ReplicationSlotRelease for ephemeral slots To: Xuneng Zhou Cc: "Zhijie Hou (Fujitsu)" , Srinath Reddy Sadipiralla , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jun 2, 2026 at 3:00=E2=80=AFPM Xuneng Zhou w= rote: > > Hi, > > On Sat, May 30, 2026 at 4:14=E2=80=AFPM Zhijie Hou (Fujitsu) > wrote: > > I'm not sure if adding an injection point for this rare case is worthwh= ile. Even > > if we were to add one, future refactoring of that function could shift = the > > position of the injection point, so its long-term usefulness is uncerta= in. I > > don't have a strong opinion on this, so I'll leave it to Fujii-San to d= ecide. I've pushed the patch. Thanks! IMO the proposed test looks a bit too narrow, so I'm not sure it's worth adding at this point. For now, I've committed only the code fix. > There's an adjacent bug around drop_local_obsolete_slots. The root > cause of them looks similar -- ReplicationSlot * is a pointer to a > reusable shared-memory array cell, not a durable identity for the same > slot. In drop_local_obsolete_slots, the issue is that the slot has > been freed after ReplicationSlotDropAcquired(false); however, another > backend may reuse the same cell before the unlock/log reads. This > seems less severe -- it does not normally corrupt slot state, because > the code only read after the drop. But it can still unlock/log > misusing the identity of a different slot. Attached a test using > injection point to reproduce it and a patch to fix it. Thanks again for the report and patch! /* Drop the local slot if it is not required to be retained. */ if (!local_sync_slot_required(local_slot, remote_slot_list)) { + bool dropped =3D false; + NameData slot_name =3D {0}; + Oid slot_database =3D local_slot->data.database; bool synced_slot; Is it really safe to read slot_database before acquiring the database lock? BTW, I'm also wondering whether it's safe for local_sync_slot_required() to access local_slot without holding a lock. Regards, --=20 Fujii Masao