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 1vYKv3-001ADt-2z for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Dec 2025 09:12:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vYKv1-004EZB-1x for pgsql-hackers@arkaria.postgresql.org; Wed, 24 Dec 2025 09:12:32 +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 1vYKv1-004EZ2-0m for pgsql-hackers@lists.postgresql.org; Wed, 24 Dec 2025 09:12:32 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vYKv0-002N9O-0u for pgsql-hackers@lists.postgresql.org; Wed, 24 Dec 2025 09:12:30 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-594330147efso6989620e87.2 for ; Wed, 24 Dec 2025 01:12:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766567548; x=1767172348; 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=/g1dbjyaQEaYwdKpEM+9GxvptAftnU8eGUZXDTfpDKg=; b=JV4lMAXWdCSVBTlXSySEnvlYPdQ7HFDam5HBhtpC9eGXLuJZQKTOeY7U5G8TUKjHZM gCYl6jYoN/2VUemHsrIHxIjBUUMGy/iOSlVRhCXUZNFt61zjh3fokZkSD0Qsqvycu0J1 w6gcm75peI+o7iPZnrzY5IyLBT6BKICZ14QgCYam3Zju3NcZg9tIQ9FsraptYPC95rgV GPQwJnkqSpmLHlgLKbPak2gPlru9MIo5ixCobA6ACUdD+DJltjL8MGN6MQB4VbKwK9u2 oF6kB9N8x5QHj0E8gMTuD/5awK6oD39gZyENIZKSp2p0lCqocFzhGej7kJEFkwjW62Hb 6y8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766567548; x=1767172348; 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=/g1dbjyaQEaYwdKpEM+9GxvptAftnU8eGUZXDTfpDKg=; b=MLiYzk1oX5mx5DTVHMZ23zSYt1KpTarBt+MezhG/dPPmPa1pVuLEBTush/NnIUB8S4 oN1t4phzNNwi6nPlFDS1Ap72Y/qH3O8788/lgz470pjZs9xmUERnU6X1aC9D6xJS51Kn ZaoBaERPSbsMBbtsXZ3v3ri5DQmmqXKj/+JZxcFDh8+PQe6K2tEzG3vIrO/Q00tae1+P Ho78WC1Xeproz8wJR7s+zP62tozgjc3SBYmN0wQM5kUdmHNIkI5p/RenlfB2q/7XKmJX RynCuSytUX0sBfmwYm9hKaooVKsiBhsXYjF3oqzDffzMc39Y+hFy0ykNuPH3xQfTAQU5 qniA== X-Forwarded-Encrypted: i=1; AJvYcCVQ6S4Mf0ohNblOVBzaUuv2w5yvR9ck947URu3e9yumqzCCyaKfBRur8B2rywGNcaCTM9zzjkXDX34LDVJp@lists.postgresql.org X-Gm-Message-State: AOJu0YxDhdo6KnewV8IS2PaUIqy+yXBR0gTceIKH61PfpqQ/4I9qc06+ ADtKao+Nn4TpGkI6nFnJX5bmCtp/t9iDj3crosgYuGlQtxHbz8Tl7bqh15AqOQO6k7I1xwiJ36S ZWDzAjK9eAqj+U39BXKm41yZu3M7lW6g= X-Gm-Gg: AY/fxX7itczjCLGPnaoLAqmqrdYmjn6vq6w6UkQEwYgvqMk+y5gtdQ6WhA1/CZeMQKP b/e/h0Oua1fvHm5ZzCL55/RFcfhI48OLGgFUQ5O905fbd/W5hxICRU6eB1vYnZkyZBDJVKMDo6G qPI5hpUAY+Tyum4Lrbdo7R5+C7LUier28R1+UctSHX2wzV4xxFI1rtmFU7yLh+ESqC3r9pUniY2 auRGCRPhmTYcQgV5BZG+EhqTGBehuquVbjGT6JOF4mz1cMd9RjY9xEGi7HFtftto1o0JBG5auBq ytRA87kXRQEzU31Wco8QLb05qC6pfw== X-Google-Smtp-Source: AGHT+IEGOYgpwKOUo1DJ9YTUmCspIL4en+NQJSSfaY3psRmUX34HknmaJP5ltLCFB1+tjlZnt17BcC/YQSDFj5d9jao= X-Received: by 2002:a05:6512:15a4:b0:59a:109c:6c19 with SMTP id 2adb3069b0e04-59a17d60871mr6516894e87.19.1766567548125; Wed, 24 Dec 2025 01:12:28 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Wed, 24 Dec 2025 14:42:15 +0530 X-Gm-Features: AQt7F2pe_RLJIW4_M6E2UTr81TRIEEKq-UCZ5OXrwCLITMy9oPFOODM5A8LYs44 Message-ID: Subject: Re: [Patch] add new parameter to pg_replication_origin_session_setup To: "Zhijie Hou (Fujitsu)" Cc: "Hayato Kuroda (Fujitsu)" , Doruk Yilmaz , "pgsql-hackers@lists.postgresql.org" 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, Dec 23, 2025 at 2:24=E2=80=AFPM Zhijie Hou (Fujitsu) wrote: > > When testing the new parameter in pg_replication_origin_session_setup(), = I > noticed a bug allowing the origin in use to be dropped. The issue arises = when > two backends set up the same origin; if the second backend resets the ori= gin > first, it resets the acquired_by flag regardless of whether the first bac= kend is > using it. This allows the origin to be dropped, enabling the slot in shar= ed > memory to be reused, which is unintended. > > About the fix, simply adding a check for acquired_by field does not work, > because if the first backend resets the origin first, it still risks bein= g > dropped while second backend uses it. > > To fully resolve this, I tried to add a reference count (refcount) for th= e > origin. The count is incremented when a backend sets up the origin and > decremented upon a reset. As a result, the replication origin is only dro= pped > when the reference count reaches zero. > > Thanks to Kuroda-San for discussing and reviewing this patch off-list. > Thanks to both of you for the report and patch. I'll look into it sometime during the next CF. --=20 With Regards, Amit Kapila.