Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nC3eD-0001UY-D8 for pgsql-bugs@arkaria.postgresql.org; Mon, 24 Jan 2022 18:00:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nC3dg-0002V1-Po for pgsql-bugs@arkaria.postgresql.org; Mon, 24 Jan 2022 18:00:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nC3dg-0002Uj-Eo for pgsql-bugs@lists.postgresql.org; Mon, 24 Jan 2022 18:00:24 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nC3dd-0002wl-Rr for pgsql-bugs@lists.postgresql.org; Mon, 24 Jan 2022 18:00:23 +0000 Received: by mail-lf1-x136.google.com with SMTP id b14so51650198lff.3 for ; Mon, 24 Jan 2022 10:00:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=KIwHp06NilpbV/7dxUvHrADPskvcnCO6Yr2c/CU/DNc=; b=Yw/DjcYqj2DaNJde8NHCLcAcQ5llSP3V72hWa8/hg1sohXtwe13SWSmjkqjCXdY2SZ mmxR9fTY+yM7dNBVJXSlbKq2wdxKwQ4We0Zy2zss2m6hdqC5LmapFYAiY7MFpTE2s4xL Ts3tPGKb7kKlJJKoI+Asc7qBc+AOK+/XqRpWa6GRck2Xn8stw8FTlqFkvTush9qwUxw9 mD884TH1g5FM1EMbJxhilg02MQYssYz1yTwi4Q6WIapPgWcmez4mKrWaEF6uOQXD+uaT YdLCUnJhOqbELROvIs8QZhVH3EjMIiXzW6hintZ+YB+RkVscSmtXQbLpjj7MVgle9S3R I49w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=KIwHp06NilpbV/7dxUvHrADPskvcnCO6Yr2c/CU/DNc=; b=JooU8HYEyS9sXQfVkRIsu7QDeV39fvJf5prZgDR5JqD8M2eaAy13oviLLP4oinKr8z 2F9CvKXYm0elCJlbNIe/IGttALbvEK7An9l/dKxdce2BXoUYQJixMCIePvLPpHzn9tm8 7nAWAz71XT2yEgGC7WmuILd6F2rVwvd1jA7OkQ3hyGAZM8im1fAPLr+tdl4BSuu8i7XR msgCYtu54M156606vYZS4u2wGccKj8iRJNUctliilFDcq4/umhzd83uqAhWiRpXlunFx zLAiGFELOIYLQg2TrZlbysr9u4wtJhIUnOtIOuU2ag+oOJGHnqUbaglzj9ZsqxVofPV3 rcFQ== X-Gm-Message-State: AOAM531C8Zl5Ic7mUNY65WfDAipAxFjcrrjynfnEuHL7HDcKjfmGuFJS KBMJAd9y7wNwCsBsXHC6Nr/cB7ZqOAg= X-Google-Smtp-Source: ABdhPJxL8C1gwRH6Dh4JSFuui3hV1jnWTEVe3uz1OrFZELI0ZfA7ZoF6/c0LSXTiMyK7P5uZTlvH8g== X-Received: by 2002:ac2:4e0b:: with SMTP id e11mr13637230lfr.296.1643047203750; Mon, 24 Jan 2022 10:00:03 -0800 (PST) Received: from [1.0.0.7] ([178.155.6.172]) by smtp.gmail.com with ESMTPSA id h13sm815018lfv.100.2022.01.24.10.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Jan 2022 10:00:03 -0800 (PST) Subject: Re: BUG #17355: Server crashes on ExecReScanForeignScan in postgres_fdw when accessing foreign partition To: Etsuro Fujita Cc: pgsql-bugs@lists.postgresql.org References: <17355-de8e362eb7001a96@postgresql.org> <9a8d0f3f-430d-024c-09f5-88a7519e9495@gmail.com> From: Alexander Lakhin Message-ID: Date: Mon, 24 Jan 2022 21:00:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------EBA650673BDF677814060D7D" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------EBA650673BDF677814060D7D Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hello Etsura-san, 18.01.2022 11:01, Etsuro Fujita wrote: > On Fri, Jan 7, 2022 at 3:19 PM Etsuro Fujita wrote: >> On Thu, Jan 6, 2022 at 9:00 PM Alexander Lakhin wrote: >>> 06.01.2022 12:56, Etsuro Fujita wrote: >>>> I haven't tried to reproduce this yet > I think a simple reproducer for this issue is: > > 1) Define the partitioned table async_pt as shown by Alexander. > 2) Run concurrent transactions as follows. > > Session A: insert into async_pt values (3000); > Session A: begin; > Session A: update async_pt set a = a; > Session B: delete from async_pt; > Session A: commit; > > The commit in Session A would cause a server crash in Session B due to > the segmentation fault. > > Also, I think a simple reproducer for the “cannot re-evaluate a > Foreign Update or Delete during EvalPlanQual” error is: > > 1) Define the partitioned table async_pt as shown by Alexander. > 2) Run concurrent transactions as follows. > > Session A: insert into async_pt values (3000); > Session A: begin; > Session A: update async_pt set a = a; > Session B: update async_pt set a = a; > Session A: commit; > > The commit in Session A would cause the transaction in Session B to > abort with that error. Thanks for the explanation and the fix! I've made a simple isolation test (see attachment) to confirm this. And it crashes without the fix as you said. With your fix it works as expected (I was wondering how "plan->operation != CMD_SELECT" with RETURNING will work and I haven't seen any issues yet.) (Besides that I've observed an infinite waiting for ShareLock with step "s1i" { INSERT INTO pt VALUES (2000); } This doesn't happen with a regular (not foreign) table.) Best regards, Alexander --------------EBA650673BDF677814060D7D Content-Type: text/x-patch; charset=UTF-8; name="test-for-bug-17355.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="test-for-bug-17355.patch" diff --git a/contrib/postgres_fdw/Makefile b/contrib/postgres_fdw/Makefile index c1b0cad453f..02150ad8e2c 100644 --- a/contrib/postgres_fdw/Makefile +++ b/contrib/postgres_fdw/Makefile @@ -17,6 +17,7 @@ EXTENSION = postgres_fdw DATA = postgres_fdw--1.0.sql postgres_fdw--1.0--1.1.sql REGRESS = postgres_fdw +ISOLATION = bug-17355 ifdef USE_PGXS PG_CONFIG = pg_config diff --git a/contrib/postgres_fdw/expected/bug-17355.out b/contrib/postgres_fdw/expected/bug-17355.out new file mode 100644 index 00000000000..1c829cd52c3 --- /dev/null +++ b/contrib/postgres_fdw/expected/bug-17355.out @@ -0,0 +1,27 @@ +Parsed test spec with 2 sessions + +starting permutation: s1i s1b s1u s2d s1c +step s1i: INSERT INTO pt VALUES (3000); +step s1b: BEGIN; +step s1u: UPDATE pt SET a = a; +step s2d: DELETE FROM pt RETURNING *; +step s1c: COMMIT; +step s2d: <... completed> + a|b +----+- +3000| +(1 row) + + +starting permutation: s1i s1b s1u s2u s1c +step s1i: INSERT INTO pt VALUES (3000); +step s1b: BEGIN; +step s1u: UPDATE pt SET a = a; +step s2u: UPDATE pt SET a = a RETURNING *; +step s1c: COMMIT; +step s2u: <... completed> + a|b +----+- +3000| +(1 row) + diff --git a/contrib/postgres_fdw/specs/bug-17355.spec b/contrib/postgres_fdw/specs/bug-17355.spec new file mode 100644 index 00000000000..b99aa50b052 --- /dev/null +++ b/contrib/postgres_fdw/specs/bug-17355.spec @@ -0,0 +1,42 @@ +setup +{ +CREATE EXTENSION postgres_fdw; + +CREATE SERVER testserver1 FOREIGN DATA WRAPPER postgres_fdw; +DO $d$ + BEGIN + EXECUTE $$CREATE SERVER loopback FOREIGN DATA WRAPPER postgres_fdw + OPTIONS (dbname '$$||current_database()||$$', + port '$$||current_setting('port')||$$' + )$$; + END; +$d$; +CREATE USER MAPPING FOR CURRENT_USER SERVER loopback; +CREATE TABLE pt (a int, b int) PARTITION BY RANGE (a); +CREATE TABLE base_tbl2 (a int, b int); +-- CREATE TABLE p2 PARTITION OF pt FOR VALUES FROM (2000) TO (3000); +CREATE FOREIGN TABLE p2 PARTITION OF pt FOR VALUES FROM (2000) TO (3000) + SERVER loopback OPTIONS (table_name 'base_tbl2'); +CREATE TABLE p3 PARTITION OF pt FOR VALUES FROM (3000) TO +(4000); +} + +teardown +{ + DROP TABLE pt; + DROP TABLE base_tbl2; + DROP EXTENSION postgres_fdw CASCADE; +} + +session "s1" +step "s1i" { INSERT INTO pt VALUES (3000); } +step "s1b" { BEGIN; } +step "s1u" { UPDATE pt SET a = a; } +step "s1c" { COMMIT; } + +session "s2" +step "s2d" { DELETE FROM pt RETURNING *; } +step "s2u" { UPDATE pt SET a = a RETURNING *; } + +permutation "s1i" "s1b" "s1u" "s2d" "s1c" +permutation "s1i" "s1b" "s1u" "s2u" "s1c" --------------EBA650673BDF677814060D7D--