Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gM359-0006Oq-CD for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Nov 2018 03:40:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gM354-0003H7-VO for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Nov 2018 03:40:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gM354-0003H0-My for pgsql-bugs@lists.postgresql.org; Mon, 12 Nov 2018 03:40:06 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gM351-0000U1-W0 for pgsql-bugs@lists.postgresql.org; Mon, 12 Nov 2018 03:40:06 +0000 Received: by mail-lf1-x12e.google.com with SMTP id l10so1521204lfh.9 for ; Sun, 11 Nov 2018 19:40:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=yyxVy2i1uQNbi/9kP8UgYrOrScsJu0CHTNwlT5hSX9M=; b=l91VcXpCANMUhWXNs/qjjwIXfsD3MQD95ishogL7igo09C9O8M7kYR+QqK/V17a097 OIV0TnS/8frZSzvULNRSAymCvycpADkbA2jALj8ufeiOxEDQSUNLO0Cfh+Jwv3uv27rU CwAi33vdzGLnx3YOGGwXLyS3k0yZBx7ul/uhcIfwr7rGS3u1QNCSffFmVd/HSrig3DiH SIRdDrjRxQorG6Fswu29CMsTMV9h0FIi+xElZiX0YVrrNHK4D+PCCpmHbM24egsY8Lvi GjuquNvrQ3R3hDelcZVy5JHAtjSy/l6cLjr4zVUI9g5e23d7TyKMSwfTdyOnmxkil8wH pyog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=yyxVy2i1uQNbi/9kP8UgYrOrScsJu0CHTNwlT5hSX9M=; b=OnmKHQdPzWvlSTx7qJzxnkiMNdR1H2i3LbAZCOtfsKAFdZqLTssvkbIbAePPjFSfAy PPncQX7tJ8fJ7tIxzqJPkreAQzh7Zj4KVO/SNjju0WclaUeJA85Hx/8JXv/2pkPvoAUw Nsr+6BD77wAifuM8nlr1dpCRS/I6tbSlTIlI/TnqPqNTSl7a5V4vv6u2NUd2lkdaNYyN GegIp2Nozhzzyg8OMI5WRF6xKPIngnu9o4aOyVhsrDD7wRCVJ5GQjXi9YOodVQ/B/NBe ROySLA3FRY8Q9bNCImaZMx6LYH6sKWLc1bJCNk7YhBRq4mGDkXvDm3DLmUhya+We5/f5 mzFw== X-Gm-Message-State: AGRZ1gIPl1u7spwqJ4giPYisZtB3wELWFlNNnhud7Ii2SfzVIDfnkqYI OMcP4Hw9lYQW1IwOLnzpUZV3qbF0 X-Google-Smtp-Source: AJdET5enOveORHSTklfpeb24XtdhKsVGLs7jo1Bm6JIRhRNu+LUalHw+lhxJjwLc6NZV1liptfZTWw== X-Received: by 2002:a19:8d01:: with SMTP id p1mr9477570lfd.149.1541994002465; Sun, 11 Nov 2018 19:40:02 -0800 (PST) Received: from [1.0.0.7] ([178.155.4.187]) by smtp.gmail.com with ESMTPSA id p67sm2786115lfe.14.2018.11.11.19.40.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Nov 2018 19:40:01 -0800 (PST) Subject: Re: BUG #15492: pg_cancel_backend(pg_backend_pid()) returns true sporadically To: Magnus Hagander , Thomas Munro Cc: pgsql-bugs@lists.postgresql.org References: <15492-9b79ce7d1e0687a9@postgresql.org> From: Alexander Lakhin Message-ID: Date: Mon, 12 Nov 2018 06:40:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------F79D2B500D5DBEF6990522B7" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------F79D2B500D5DBEF6990522B7 Content-Type: multipart/alternative; boundary="------------27AF08078C214F6464FE4B87" --------------27AF08078C214F6464FE4B87 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 09.11.2018 17:48, Magnus Hagander wrote: > On Fri, Nov 9, 2018 at 2:25 AM Thomas Munro > > > wrote: > > We saw a variant of this problem on appveyor (a Windows build-bot) > when testing Daniel's patch to add an optional message (search for > "timing"), and it was fixed as part of that patch, for the new code in > that patch: > > https://www.postgresql.org/message-id/flat/C2C7C3EC-CC5F-44B6-9C78-637C88BD7D14@yesql.se > > Perhaps other pre-existing tests need similar treatment? > > > Ah yes, that seems to be the same thing, and yes that seem like a > reasonalbe solution. So something like: > +select case > +       when pg_cancel_backend(pg_backend_pid()) > +       then pg_sleep(60) > +end; >   > Alexander, can you check to see if making that change solves the issue > on your machine? Yes, after applying the attached patch, the issue is gone. Best regards, Alexander --------------27AF08078C214F6464FE4B87 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
09.11.2018 17:48, Magnus Hagander wrote:
On Fri, Nov 9, 2018 at 2:25 AM Thomas Munro <thomas.munro@enterprisedb.com> wrote:
We saw a variant of this problem on appveyor (a Windows build-bot)
when testing Daniel's patch to add an optional message (search for
"timing"), and it was fixed as part of that patch, for the new code in
that patch:

https://www.postgresql.org/message-id/flat/C2C7C3EC-CC5F-44B6-9C78-637C88BD7D14@yesql.se

Perhaps other pre-existing tests need similar treatment?

Ah yes, that seems to be the same thing, and yes that seem like a reasonalbe solution. So something like:
+select case
+       when pg_cancel_backend(pg_backend_pid())
+       then pg_sleep(60)
+end;
 
Alexander, can you check to see if making that change solves the issue on your machine?
Yes, after applying the attached patch, the issue is gone.

Best regards,
Alexander
--------------27AF08078C214F6464FE4B87-- --------------F79D2B500D5DBEF6990522B7 Content-Type: text/x-patch; name="fix-pg_cancel_backend.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix-pg_cancel_backend.patch" diff --git a/src/test/regress/expected/hs_standby_functions.out b/src/test/regress/expected/hs_standby_functions.out index e0af677ea1..7714d7bdd6 100644 --- a/src/test/regress/expected/hs_standby_functions.out +++ b/src/test/regress/expected/hs_standby_functions.out @@ -36,5 +36,8 @@ from pg_locks where virtualxid = '1/1'; (1 row) -- suicide is painless -select pg_cancel_backend(pg_backend_pid()); +select case + when pg_cancel_backend(pg_backend_pid()) + then pg_sleep(60) +end; ERROR: canceling statement due to user request diff --git a/src/test/regress/sql/hs_standby_functions.sql b/src/test/regress/sql/hs_standby_functions.sql index 251bac0a43..23795a8668 100644 --- a/src/test/regress/sql/hs_standby_functions.sql +++ b/src/test/regress/sql/hs_standby_functions.sql @@ -21,4 +21,7 @@ select locktype, virtualxid, virtualtransaction, mode, granted from pg_locks where virtualxid = '1/1'; -- suicide is painless -select pg_cancel_backend(pg_backend_pid()); +select case + when pg_cancel_backend(pg_backend_pid()) + then pg_sleep(60) +end; --------------F79D2B500D5DBEF6990522B7--