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 1qpmhn-006xdP-8E for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Oct 2023 09:37:40 +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 1qpmhl-00Bxlj-0b for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Oct 2023 09:37:37 +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.94.2) (envelope-from ) id 1qpmhk-00Bxl9-18 for pgsql-hackers@lists.postgresql.org; Mon, 09 Oct 2023 09:37:37 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qpmhf-000lOP-MT for pgsql-hackers@lists.postgresql.org; Mon, 09 Oct 2023 09:37:35 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 625D53200941; Mon, 9 Oct 2023 05:37:29 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 09 Oct 2023 05:37:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1696844248; x=1696930648; bh=3B jtTx43Ocsd5aN1eQLXvQ0E8Agvi5WvoJKAno/wy/4=; b=ZmHsI3a1ZlR9uNHR1D 37ailhzvOCmSsZHNRB1p7MpnFSWHcSmzjUoenhRY/R4A9xlU/Lhr+bopxRDoAcyK NYFPHunKxCRlMTKbNhjx0uSB2i+aTyqnfFmj0JWek+HdJ6H5eOOEvxi5AuJQ+2Aw +riQFNj0h76kKeyxtZS6m2lzejWwvy3EKCl9VXo9eJA9Om262j/FB7OovpostCKA qkBSnA27MY1W61U+SCVGaasl9wrhk+vzjwS922ZB5yFSDrejOTvCTLmDuf28k5Wv CI7uT6jlocmRJKfZjyZprlC8sJj6vD4++/564Qaa2t9ih5VCtrXMtekxmHKqREn2 Lt7Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1696844248; x=1696930648; bh=3BjtTx43Ocsd5 aN1eQLXvQ0E8Agvi5WvoJKAno/wy/4=; b=H161VCg1wfVPwiUETNtk/Gr1jGZ4A VfrUdGZw+sVedBG9HOhKCDOCZqDZZjdgnva/71ue5jzd+xTdaqkFjSuhhpkAoVoc xZLSMJ2kdVAsyIuapBmK5oWX1jdN7aUV4zmd00n+bDHsjxHS2PiFj/Oxs9ySSwmR nF/Ssx9VsIOMDsl5yIpSs9FCa4SAF03BqaOK6rsiBA3vITMacFsWMDwti65oaEWj Nqi59nupzO0gJXPnJKvyE5aJcCiKqgIq/1DJwtsxatyK08whrKDVJ2SpwOSM6GFX DwxRjbNbQWZvhpalJOUKn9t6Vcpa096/g4/GYGoBy6C3MmINXPlcANSsQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrheefgddukecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeetleeifedufffhhfdtteelgeeg geffhfekueevteeigfduudevudetgfegiedvjeenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 9 Oct 2023 05:37:26 -0400 (EDT) Date: Mon, 9 Oct 2023 18:37:21 +0900 From: Michael Paquier To: Tom Lane Cc: Bharath Rupireddy , "Drouvot, Bertrand" , PostgreSQL Hackers , Andres Freund Subject: Re: Add a new BGWORKER_BYPASS_ROLELOGINCHECK flag Message-ID: References: <566c1686-c80b-4d4a-b496-b00ac428a095@gmail.com> <83f72bb9-f3cf-4344-8d4d-45e128813d58@gmail.com> <26e7cd6a-6dd1-4b08-975b-62603eeb6f3f@gmail.com> <3365937.1696801735@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Cox21b07RL+OokBo" Content-Disposition: inline In-Reply-To: <3365937.1696801735@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Cox21b07RL+OokBo Content-Type: multipart/mixed; boundary="YhwNsCMKBcKqBLFR" Content-Disposition: inline --YhwNsCMKBcKqBLFR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Oct 08, 2023 at 05:48:55PM -0400, Tom Lane wrote: > There have been intermittent failures on various buildfarm machines > since this went in. After seeing one on my own animal mamba [1], > I tried to reproduce it manually on that machine, and it does > indeed fail about one time in two. The buildfarm script is not > managing to capture the relevant log files, but what I see in a > manual run is that 001_worker_spi.pl logs this: Thanks for the logs, I've noticed the failure but could not make any sense of it based on the lack of information provided from the buildfarm. Serinus has complained once, for instance.=20 > Since this only seems to happen on slow machines, I'd call it a timing > problem or race condition. Unless you want to argue that the race > should not happen, probably the fix is to make the test script cope > with this worker_spi_launch() call failing. As long as we see the > expected result from wait_for_log, we can be pretty sure the right > thing happened. The trick to reproduce the failure is to slow down worker_spi_launch() before WaitForBackgroundWorkerStartup() with a worker already registered so as the worker has the time to start and exit because of the ALLOW_CONNECTIONS restriction. (SendPostmasterSignal() in RegisterDynamicBackgroundWorker() interrupts a hardcoded sleep, so I've just used an on-disk flag.) Another thing is that we cannot rely on the PID returned by launch() as it could fail, so $worker3_pid needs to disappear. If we do that, I'd rather just switch to a specific database for the tests with ALLOWCONN rather than reuse "mydb" that could have other workers. The attached fixes the issue for me. -- Michael --YhwNsCMKBcKqBLFR Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="worker_spi_fix.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/test/modules/worker_spi/t/001_worker_spi.pl b/src/test/mod= ules/worker_spi/t/001_worker_spi.pl index 06bb73816f..044e208812 100644 --- a/src/test/modules/worker_spi/t/001_worker_spi.pl +++ b/src/test/modules/worker_spi/t/001_worker_spi.pl @@ -105,30 +105,31 @@ postgres|myrole|WorkerSpiMain]), ) or die "Timed out while waiting for dynamic bgworkers to be launched"; =20 # Check BGWORKER_BYPASS_ALLOWCONN. -$node->safe_psql('postgres', q(ALTER DATABASE mydb ALLOW_CONNECTIONS false= ;)); +$node->safe_psql('postgres', q(CREATE DATABASE noconndb ALLOW_CONNECTIONS = false;)); +my $noconndb_id =3D $node->safe_psql('mydb', + "SELECT oid FROM pg_database where datname =3D 'noconndb';"); my $log_offset =3D -s $node->logfile; =20 -# bgworker cannot be launched with connection restriction. -my $worker3_pid =3D $node->safe_psql('postgres', - qq[SELECT worker_spi_launch(12, $mydb_id, $myrole_id);]); +# worker_spi_launch() may be able to detect that the worker has been +# stopped, so do not rely on psql_safe(). +$node->psql('postgres', + qq[SELECT worker_spi_launch(12, $noconndb_id, $myrole_id);]); $node->wait_for_log( - qr/database "mydb" is not currently accepting connections/, $log_offset); + qr/database "noconndb" is not currently accepting connections/, $log_offs= et); =20 $result =3D $node->safe_psql('postgres', - "SELECT count(*) FROM pg_stat_activity WHERE pid =3D $worker3_pid;"); + "SELECT count(*) FROM pg_stat_activity WHERE datname =3D 'noconndb';"); is($result, '0', 'dynamic bgworker without BYPASS_ALLOWCONN not started'); =20 # bgworker bypasses the connection check, and can be launched. my $worker4_pid =3D $node->safe_psql('postgres', - qq[SELECT worker_spi_launch(12, $mydb_id, $myrole_id, '{"ALLOWCONN"}');]); + qq[SELECT worker_spi_launch(12, $noconndb_id, $myrole_id, '{"ALLOWCONN"}'= );]); ok( $node->poll_query_until( 'postgres', qq[SELECT datname, usename, wait_event FROM pg_stat_activity WHERE backend_type =3D 'worker_spi dynamic' AND pid IN ($worker4_pid) ORDER BY datname;], - qq[mydb|myrole|WorkerSpiMain]), + qq[noconndb|myrole|WorkerSpiMain]), 'dynamic bgworker with BYPASS_ALLOWCONN started'); =20 -$node->safe_psql('postgres', q(ALTER DATABASE mydb ALLOW_CONNECTIONS true;= )); - done_testing(); --YhwNsCMKBcKqBLFR-- --Cox21b07RL+OokBo Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmUjydEACgkQnvQgOdby QH0SVg//dtcjAEJ8JqXFzVRpXul+wpPjiGYPVBUuBn2ayhcHboUvICYiW9Cik2LQ fjl02xEn7i8WnE168Vcxexx9iQePHWMDfeOF719kJUPRbsZDmUu1Lp+vZfXt3tAX CLJuenGd86DszLyxFu3qel7m8Y3cDPrErc8FfLXFrDO6ndD9qZ84KOHWfG8xMhy5 rahjG92dgWsFjZB69fUgCizLtU6x1pF3yUgwcF6TFMTTVsSKVt4rphfYGOTIGb5r QcN8MoudnV5EJe9A6jZI9MJTcffvJAp03IW11oQKNSWFVByI7WuZeqcI+DmINqI6 yTpYrEP55ril6xJ4RjKjd8NsubnB2HDlUgOqw67XbXdrM+e8nPAjzbTPe++cLTSg uWwjqOg01a48Vjy4Kr+5XOrcRjQLJ06hZ/0AGdfrast2X9Z7C/4GIWGaOUs1ejCf J9zWEQKFdfmvIaucVGRHRw16m/93lVYlnC4GTKj+QKJzH6vYUi9uhFfY93MXKra6 IxAmGu1mzdjghQ1QZON3Vv7yLKBystAudCL5NJx2gTbjglwxPgqG4yJTgIiYzfkQ w4oLdFpJRiSORwC4svqVR866M4RZDtXEtoEaq0EkdWdcBPD3uwdgaUbm89XxiKUw 4SKxXrDb8Acy6+V9tMSc/Y+bS/Q6+8LxFJmMP0fMlowzgx+ZM3M= =fWHW -----END PGP SIGNATURE----- --Cox21b07RL+OokBo--