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 1wSsJ5-000AE3-1q for pgsql-hackers@arkaria.postgresql.org; Fri, 29 May 2026 08:11:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wSsI4-001x2M-0H for pgsql-hackers@arkaria.postgresql.org; Fri, 29 May 2026 08:10:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wSsI3-001x2E-2S for pgsql-hackers@lists.postgresql.org; Fri, 29 May 2026 08:10:00 +0000 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wSsI1-000000005hp-2MfH for pgsql-hackers@lists.postgresql.org; Fri, 29 May 2026 08:09:58 +0000 Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-7dcdd23fcdfso7399517a34.3 for ; Fri, 29 May 2026 01:09:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780042197; cv=none; d=google.com; s=arc-20240605; b=a1gYUzdjKBEbb4Rogj4qaSEPmxTnBZmSxxqcfFOtlja9gROOs93PHi1N/L07UiWS+Q MxhkN2c8xxMnJ1RJz77Gi9dd13Kqd+V1TtWcQuCVoDD1GQUuBvonx9dg7sHkAeZIjMIu R2WBVkuaQzK0dyAFnfEJsrQLBmy8i2wFBGlyGS+hyy6W9HePkco2J5U0JINlL7upPdLs XlwniEpP+bYnXQRhaxIyEqWynijrxpqfMJdk6Jj0TA/6eG35Bed2m+D5og8o4xp04AzV 13RIsrv3HWEyYPZfAogf1u0+7K7FCQhWZtXwF/4br8VzfAyX76d2KajSYxOB8wyyOGmt V0Pw== 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=VTYcOf534+l4yuOpfgcUd7BScNZvxxeSxJbjcCttIao=; fh=Ti5UUWWnIawXjRDrxK96yl2MCM81GcRJ2EeXAktfwrY=; b=QeQDhL8btdGQAuzSkJHZ1SsNdMPKdMOt2z+BjeT7hHVvucJuUEw+7cxh6tEnyyHKQA YJ16cyN0fuoA0wPawkvNOrnLH9exrh1/jVZ/09vrG4RdIwXQXmIvOpVf8WEf7rwsg2ut qE8ZpiAohQzFwEB7okZ6HOW/5QSdgVWHPUXLRjlDmBgYSAFEoyYyvPc2gTSQeZ87XSAq QNF/8Ki4eNCkAcve7EHOjPJzSleherIVNUDCTHJQfANH01xZxlCcU4aqgfpNdPEQ41Fr ofrota9uWrq51LR4+KYPw3QnUg+MikZSE8ZtDjcWdWO9aDQUJ1CLaFFRHsHYvQCr0h53 VcGw==; 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=1780042197; x=1780646997; 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=VTYcOf534+l4yuOpfgcUd7BScNZvxxeSxJbjcCttIao=; b=F3TptaUwl7pwcxpj+4FwPZ/lEixKPhuUoH7fkzlkHTVCFpTywTEbEEVjfGkbmXQ9c6 ihfWb8R2pzukCUtPd4QLKIbqyKC2TCM8it4D1jl1zu6UR4vSyx3A1AOOekf6e02/rco6 LLS+k/BsDNkXlKj0J9EH4OmAaR8QL/ZHvdh/A0bA2uz1gyOcJJd2AxpqD3eL6yBWBlIw cEMs2BfRoPkMcKy/0HMiQ/w9ALJyndhecxwARAywOiFtVAW8Faroozh8xGn0Hg174Bk8 cXvIHa/HYCjDVAgi4WdzWC0i6MnHhoiN/mdV1BImP+xpVsalGAOD67l3uAdn05oyJ04s snhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780042197; x=1780646997; 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=VTYcOf534+l4yuOpfgcUd7BScNZvxxeSxJbjcCttIao=; b=cFtzIWOl8UAiHPa0pfm7MLuEdiuOQBK4UfgMtfNmtvMMJEFvqRg4tX0OdBJJ0GWxbH mjHQYdjSNXnuMPsCr1GIDpQjIMBQmU2BQxmrHGI6lzIUko8aX4lXVVzQOHr8Y2QR9lCU OWmP/nt7B2nZhAyv+2LKAyTd6w9QipgsrzGmLqX0pepHCjxF5OSJfeJy/MyTsD9cyIBY QnJnzb+9Q6qxl3TY3m8AKn/3EGBSeU+N0mBxIjtSEuspf8EzBesOJ0HAw7PsVqaoIo9M NvqbVWKymCGglCz+OUi/P/fSC9wvWgqnJw43xUzUZcdiFH8vGY86ls3OR8nMwqAHwpMx ei+A== X-Gm-Message-State: AOJu0YyHoUQIwWxeCArO/+4u5XnMK6y9oGy32Ic1dzu8Xd/Z975YOiL9 zSZ7wQZPh4cWybD0bbqN5gTq4hsCvbvrtx1byOg3njdnsqsumfJPZ0thg62/ytqEVTJ9dYJofKz vCljQZdKce+C40YTZZqwVWZPXOoJVnyI= X-Gm-Gg: Acq92OGkeQy50jwN/e7ZnWgmFknxpxG5+6HLFPNLNAU9lhDWZG1XfDDsj8EOCuNqxrE t2rXv2aDIqbtFi/SxB5hix9gkE/Ru/4FylN+J/OjchYrDPgBlLO/UEkovWENZSzIGZ/3dboJdG8 ka4S3CcJ/xnLHco+7d3Ek81IDtGAN+jJm8jQ6G7iuchcn5tX0QaojG1Aj81I7i/4/lMSAk5OuLS NPh/EHn/aP3u6Tb7JNtciJfN+VSTUpmKOaUiaVFJMhYlZlKyCm/Zt2kykrxn3qaLQWBMUsU9tOr W/c0RoJ4kqVAU/n2w0hMbeY8jWtoh4y9bRqzuKVfYz9Covbb2Q== X-Received: by 2002:a05:6820:4df4:b0:69c:5d2b:407c with SMTP id 006d021491bc7-69e040b2ca9mr1049637eaf.58.1780042197249; Fri, 29 May 2026 01:09:57 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Fujii Masao Date: Fri, 29 May 2026 17:09:44 +0900 X-Gm-Features: AVHnY4I4__PvQ5i4urj7ZZSOynH4Q_9v3W_qj0-NR9_NN71WZo9V1Tv5xzuE4_U Message-ID: Subject: Re: Fix race in ReplicationSlotRelease for ephemeral slots To: "Zhijie Hou (Fujitsu)" Cc: 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 Wed, May 27, 2026 at 8:50=E2=80=AFPM Zhijie Hou (Fujitsu) wrote: > > Hi, > > While testing the slot release logic, I noticed a bug in > ReplicationSlotRelease() where it may access a replication slot array ent= ry that > has already been released by itself. > > The detail is: When releasing an ephemeral replication slot, > ReplicationSlotRelease() first drops the slot via ReplicationSlotDropAcqu= ired(). > After this point, the slot's shared memory slot array entry can be immedi= ately > reused by another backend creating a new slot. > > However, ReplicationSlotRelease() continued executing common cleanup code= that > still dereferenced the old slot pointer and updated shared memory fields = such as > effective_xmin. If the slot array entry had already been reallocated, the= se > writes could inadvertently affect a different, unrelated slot. Good catch! > I am attaching a patch that avoids touching slot shared-memory state afte= r > dropping an ephemeral slot. Keep the post-release shared-memory updates o= nly for > non-ephemeral slots, where the slot remains valid after release. Thanks for the patch! It looks good to me. Barring any objections, I will commit it. > I haven't attached a test for this fix, as the change is straightforward = and the > likelihood of encountering this bug is low, so it may not be worth adding= test > cycles for it. +1 Regards, --=20 Fujii Masao