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.94.2) (envelope-from ) id 1uwxYA-0099aQ-1i for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Sep 2025 06:46:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uwxY8-00D1xe-5I for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Sep 2025 06:46:24 +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.94.2) (envelope-from ) id 1uwxY7-00D1wC-QV for pgsql-hackers@lists.postgresql.org; Fri, 12 Sep 2025 06:46:24 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uwxY3-000KWU-1Y for pgsql-hackers@lists.postgresql.org; Fri, 12 Sep 2025 06:46:23 +0000 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-b0473327e70so254856666b.3 for ; Thu, 11 Sep 2025 23:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1757659580; x=1758264380; darn=lists.postgresql.org; h=message-id:date:content-transfer-encoding:mime-version:comments :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p6ZevQ4CVORkVwHyBEswNCJJ1BqNnK+VWpmPRKdJ/lw=; b=j+/ZgVPqjcOcJkQWU6ZqT7gIp9maoMlZjYibO1Z7ARlKL2z/osn/vp1+rkF1oWbz7P Knj2xUThxG4an5u9HrUYJMcp7URLF4xvDIMU1We1XN1yZkWrfNMQCJhqXnk5tvAHoQ8z 9e2qtuOpseSIcvmgO2auT4sEphsfQ4UZShb7HMMCov6bCb7zS1KO0zOBVa7ydKVTiJKF EDRlefcThblZ95gbgz90855cPOoCif74Jc7PL9Ztx/4vJEZ+yPDjR9A7oVqpCVih2hn7 QBpOQ23mG7O8ShTQBRP1EKeLZgkrulH6xuhEBUXTVJUTOtVP4W0OdSgdvYU+A5lUe2yX owpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757659580; x=1758264380; h=message-id:date:content-transfer-encoding:mime-version:comments :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=p6ZevQ4CVORkVwHyBEswNCJJ1BqNnK+VWpmPRKdJ/lw=; b=KidqDFTcvuXjZTnQhgHN+jEUz2lm4KJGZCS9FylOQtdcWbBu7xzFz8DBNIIGsZT++y AKSxYLgIPr1D6aoAUYjXEKSH0CPminLJktMT2a1K3DcF9l3uWyhQjo8P1UVm7veZGRvY WXkme98UnleFQRfWMEWAlG5yCiMAzdfyXN0JpMjNiAIyEaAWXrPgoJk+1xrSg2OfOozF OOJx77ka8uGaYBfYF85sfYYWyHyav8lmsJpTbMnrtX9s79hBRupakfkZxIFM/BzOnrOq 5S2oCe8aa7oVJ00Z2prjr8JaQJhXodUy7dW/5UePN8AagNUCkF1+oOsmF3kI8+bgf4Qh gaKA== X-Forwarded-Encrypted: i=1; AJvYcCWkLnJbjemYXaqw0H8RFyL1MivfK3HRkqWlkM/e9DUJwccoTNbaVgmJsL7cnvSpmoBNgPleUJRqp1++oCz0@lists.postgresql.org X-Gm-Message-State: AOJu0Yxs/GeNEKMcDvPVfwnlxfuyHe6rJbCpWAyMjT1S0d+cjH/OwfD6 OK6uZlbpSl3P1MaJWClq2zUvhkgobUaVaR2OwGlrzAXq6VK9Rljij4a43QmH8GgjAYM= X-Gm-Gg: ASbGnct4NInijxQ6NTEa2CN/bTwY9GijuFagVOrZE+Zui1Daj5iN32m3L2SamsXA2le 5X98HMaT708FLyO6Ijb7rlGrcARlRtK7fa3xz7heXTyO4S+GlxZ6Y8/73jACWOnlfvXswupMC8T dJcho/KVyKxMUD3171a9Rz0RjNISaDVgycZ3ZmBEZCIei3uYsDrV0SHesdPQTlNT2FugWzJSfVk /rGfxGvzfeYWqweTeFPkroBBfXPa0lQaX4glbqJNzPjDqebfeZMkIXF25MYNxl32+zakTtkWjBt Brg3yQDPI/J/PU4CdygOy4kSRAKWfue83bcdNvhTEGu3STOcJB/fFvWIdZmgHaY4B4R1bwuwJBO 86BjdmFekaUvs6mDx62WqgVgGe22wrqBOhmiw X-Google-Smtp-Source: AGHT+IHiTmO6h93GdtGCowjJjeUitupyFyW1xzZrmACuDqdZMgJDmIUh1Pj/UXM5vulK9h83fyR9dg== X-Received: by 2002:a17:907:7fa7:b0:b04:58f8:16e3 with SMTP id a640c23a62f3a-b07c35c2fd1mr159983566b.24.1757659579525; Thu, 11 Sep 2025 23:46:19 -0700 (PDT) Received: from localhost (109-81-168-144.rct.o2.cz. [109.81.168.144]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b07b32f1edasm310090066b.89.2025.09.11.23.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Sep 2025 23:46:19 -0700 (PDT) From: Antonin Houska To: "Euler Taveira" cc: =?us-ascii?Q?=3D=3FUTF-8=3FQ=3F=3DC3=3D81lvaro=5FHerrera=3F=3D?= , pgsql-hackers@lists.postgresql.org Subject: Re: Unexpected changes of CurrentResourceOwner and CurrentMemoryContext In-reply-to: <267a39fd-8b8a-48b0-8f99-b4257482ac95@app.fastmail.com> References: <202509111800.kp6xfq6pnke7@alvherre.pgsql> <267a39fd-8b8a-48b0-8f99-b4257482ac95@app.fastmail.com> Comments: In-reply-to "Euler Taveira" message dated "Thu, 11 Sep 2025 17:38:23 -0300." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 12 Sep 2025 08:46:18 +0200 Message-ID: <6242.1757659578@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Euler Taveira wrote: > On Thu, Sep 11, 2025, at 3:05 PM, =C3=81lvaro Herrera wrote: > > On 2025-Sep-03, Antonin Houska wrote: > > > >> When working on the REPACK command, we see an ERROR caused by unexpect= ed > >> change of CurrentResourceOwner [1]. I think the problem is that > >> reorderbuffer.c does not restore the original value after calling > >> RollbackAndReleaseCurrentSubTransaction(). The attached patch tries to= handle > >> the call like other callers throughout the tree do. > > >=20 > Interesting. I'm wondering that if this patch is applied we could remove = the > following code >=20 > /* > * Logical decoding could have clobbered CurrentResourceOwner during > * transaction management, so restore the executor's value. (This is > * a kluge, but it's not worth cleaning up right now.) > */ > CurrentResourceOwner =3D old_resowner; >=20 > from pg_logical_slot_get_changes_guts and LogicalSlotAdvanceAndCheckSnapS= tate > functions too. IIUC the referred code is a band-aid that will be improved > someday. Even though we're fixing the likely reason of this problem, we cannot be 10= 0% sure that no other problem like this still exists. So I'd not remove this assignment. Maybe add Assert(CurrentResourceOwner =3D=3D old_resowner) in f= ront of that, and adjust the comment? > > I have registered this as > > https://commitfest.postgresql.org/patch/6051/ > > > > I've been wondering whether this should be backpatched. In principle > > this is a bugfix, so it should, but I don't offhand recall any cases > > where failure to set the current context/resowner in the other > > reorderbuffer.c users causes a live bug, so ... maybe master only? I'm > > wondering if it's possible where anybody _depends_ on the current > > behavior, but I suppose that's quite unlikely. > > >=20 > I would say apply it to master only. If/when we have a bug report we can > backpatch it. +1 > Per the crash description, I'm not sure we can create a > reproducible test case with the current supported commands. Am I wrong? It seems so, at least with he "CurrentResourceOwner =3D old_resowner" assig= nment in place. REPACK CONCURRENTLY exposes the problem a bit more because it has= at least one kind of resource open during logical decoding: relation. --=20 Antonin Houska Web: https://www.cybertec-postgresql.com