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 1vch9T-009j84-1V for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jan 2026 09:45:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vch9S-0019PI-1L for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Jan 2026 09:45:27 +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 1vch9S-0019PA-0N for pgsql-hackers@lists.postgresql.org; Mon, 05 Jan 2026 09:45:26 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vch9Q-004cjy-1g for pgsql-hackers@lists.postgresql.org; Mon, 05 Jan 2026 09:45:26 +0000 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-34b75f7a134so10095101a91.0 for ; Mon, 05 Jan 2026 01:45:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767606323; x=1768211123; 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=a+tK3YjkmxcYVLhW5+u9OhOVeATHL2cprz1p+1d7bDI=; b=Pq3asxUJjFGX/wnMxvlP5D1rI8O+2evYn1jPQTofe9EuH6GZFNLuNoo0yDz70eEmMU xRm/stfi2l4+Pse23ALw345U7BKWIdVC7hsbVLNhjCevU1/0r/8dzGzFKVenzs/Uapni 2QXr6RJau/ROZMfr0ALMY6zrDYf7b1OfXw9N2p4e84j7hh8xiLxLCOrvR90UtkvgHsTY tp/epcdTr1Qt0lD9xGrY6wb9GpTAUcJIN4lV5QuYaEPkhO2/kqrBUD1pq2Xu0HbVkHR/ rhYyhx7vPdh74tnJCBgrs3jISicRgWs3nl6BNu/7ppJd9X3IYC7RJNIBWn5wmXK6q1tP TUug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767606323; x=1768211123; 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=a+tK3YjkmxcYVLhW5+u9OhOVeATHL2cprz1p+1d7bDI=; b=qQdgF44CGs5lTlaV2djnfXhN/Mk7ivR0wx0Umr8rzpM2DQW/5NdLakuKD6qfZErdpC B08SQXigT14ZHn1F9fjAvgLr4yfxfn/HhvJsV5ovGM48AK5Qn2ilKimrnIwPf2J4ybqV bvnME/aSB0VtTr3Uu1u+iPk3M2zWoNQ8BBv19DVQ97xSS4hmJ21/863tvumXiah/hm2k N5LgfFM+x9F7oJl6ypJMgQUhiAJ3Np71cJEvx1AzSEOojz7RbPcOO9iRdOXsrjOFmjjJ 1tpIFDmB3Vzc8JRH9kyjVR3GWsUJIHoGuGGmCstchhAEXERd34U0ZiqTJEK/ePCVtBFH bG1Q== X-Forwarded-Encrypted: i=1; AJvYcCV2nKUZJHWU+s/L6H5ZHUx5kfIFhKY6Ct6kJokc8n25muyU/5F0LA/Yqa+eOd5vkQ1Ddk9YGmYZ/fPYU1uz@lists.postgresql.org X-Gm-Message-State: AOJu0Yx8SwG4UdJq7qdgATUUJ22kuyJ6FCtVKWjYaLQcTfpM6GYPc5gJ LztLae78tlbKER0BGfF50hhis8d+YoJ3GomgWq2r7Tnw7mHeFtGVgVCOcQWUAAk4g34p0gl5n8D BgQfC1zUi8pNXlquvIlU9CBO/t8AF/D0= X-Gm-Gg: AY/fxX5kRHBqtASfrO5wl8PWB/wMKLzbExrt1bwnEPD1dqJwL/VrMe5zFzm1LQbEae1 YFRRLYWELQaQkKv5yOOlxyR3Zkt4+sBrPRVBuNtx0WPexv68ROEXRJj9SBui0DcREa8bsYREusc Ds15Avj8gc/MhHKjfuSaxEdVpNVkMm9i1B93KJHHRkS1+S6+NDQyAOu6B51k+NXPDo35SzfQ1Wx H+MHIcOwSN5UMoSz4OOuWk2yuReoks4aQpFHje+6j3Q9sYd50KzfMybDvBhC2QorJqhSu6lamtp y2lYlH4loIrTlGh+g0cfPCDcaj/k7R/L7OCNOPOiuPIa225Soxw= X-Google-Smtp-Source: AGHT+IHkBDan1jXKdKtBAGYWrzGTqMdKXZWhsdopLkMmRmq8irEhjgQhw211GBU99pa0nY7Nea7Kp6iOpDSN7LDU6wI= X-Received: by 2002:a17:90b:2246:b0:34c:2db6:57a7 with SMTP id 98e67ed59e1d1-34e921131b8mr41723003a91.8.1767606322568; Mon, 05 Jan 2026 01:45:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Mon, 5 Jan 2026 15:15:08 +0530 X-Gm-Features: AQt7F2qGhUerJA1tbdgl4hbjm9h94N6Fos4Ccm7V3DFpl9Q1oAiO2ZTWn3DAO3s Message-ID: Subject: Re: [Patch] add new parameter to pg_replication_origin_session_setup To: "Zhijie Hou (Fujitsu)" Cc: "Hayato Kuroda (Fujitsu)" , Amit Kapila , Doruk Yilmaz , "pgsql-hackers@lists.postgresql.org" , shveta malik 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: > > Hi, > > 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 Hou-San and Kuroda-San. What should be the expected behavior when Session1 resets the origin (changing acquired_pid from its own PID to 0), while Session2 is already connected to the origin and Session3 also attempts to reuse the same origin? Currently it asserts: Session1: select pg_replication_origin_create('origin'); SELECT pg_replication_origin_session_setup('origin'); Session2: SELECT pg_replication_origin_session_setup('origin',48028); Session1: SELECT pg_replication_origin_session_reset(); Session3: SELECT pg_replication_origin_session_setup('origin'); This asserts at: TRAP: failed Assert("session_replication_state->refcount =3D=3D 0"), File: "origin.c", Line: 1231, PID: 48037 thanks Shveta