pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Cc: Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Andres Freund <andres@anarazel.de>
Subject: Re: Add a new BGWORKER_BYPASS_ROLELOGINCHECK flag
Date: Mon, 9 Oct 2023 18:37:21 +0900
Message-ID: <ZSPJ0dKz4fdjFs5n@paquier.xyz> (raw)
In-Reply-To: <3365937.1696801735@sss.pgh.pa.us>
References: <566c1686-c80b-4d4a-b496-b00ac428a095@gmail.com>
	<ZR0EEUyWA1Nuz6CK@paquier.xyz>
	<83f72bb9-f3cf-4344-8d4d-45e128813d58@gmail.com>
	<ZR5FRByOl2y8dORo@paquier.xyz>
	<26e7cd6a-6dd1-4b08-975b-62603eeb6f3f@gmail.com>
	<CALj2ACUJf8ftjiTiNfuVKTvUM3N++dWKnhBOg1EJ29CwoTkXew@mail.gmail.com>
	<ZR9QJrNJ8lJDZ41P@paquier.xyz>
	<ZR-pSNRTY2izuNdg@paquier.xyz>
	<ZR_AESc5tptmpP9t@paquier.xyz>
	<3365937.1696801735@sss.pgh.pa.us>

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. 

> 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

Attachments:

worker_spi_fix.patch (text/x-diff, 2.2K) download diff --git a/src/test/modules/worker_spi/t/001_worker_spi.pl b/src/test/modules/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"; # 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 = $node->safe_psql('mydb', + "SELECT oid FROM pg_database where datname = 'noconndb';"); my $log_offset = -s $node->logfile; -# bgworker cannot be launched with connection restriction. -my $worker3_pid = $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_offset); $result = $node->safe_psql('postgres', - "SELECT count(*) FROM pg_stat_activity WHERE pid = $worker3_pid;"); + "SELECT count(*) FROM pg_stat_activity WHERE datname = 'noconndb';"); is($result, '0', 'dynamic bgworker without BYPASS_ALLOWCONN not started'); # bgworker bypasses the connection check, and can be launched. my $worker4_pid = $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 = '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'); -$node->safe_psql('postgres', q(ALTER DATABASE mydb ALLOW_CONNECTIONS true;)); - done_testing();
signature.asc (application/pgp-signature, 832B) download

view thread (41+ messages)  latest in thread

Message-ID: <ZSPJ0dKz4fdjFs5n@paquier.xyz>
Permalink:  ../ZSPJ0dKz4fdjFs5n@paquier.xyz/
Also on:    postgresql.org/message-id/ZSPJ0dKz4fdjFs5n@paquier.xyz

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: michael@paquier.xyz, tgl@sss.pgh.pa.us, bharath.rupireddyforpostgres@gmail.com, bertranddrouvot.pg@gmail.com, andres@anarazel.de
  Subject: Re: Add a new BGWORKER_BYPASS_ROLELOGINCHECK flag
  In-Reply-To: <ZSPJ0dKz4fdjFs5n@paquier.xyz>
  References: <566c1686-c80b-4d4a-b496-b00ac428a095@gmail.com> <ZR0EEUyWA1Nuz6CK@paquier.xyz> <83f72bb9-f3cf-4344-8d4d-45e128813d58@gmail.com> <ZR5FRByOl2y8dORo@paquier.xyz> <26e7cd6a-6dd1-4b08-975b-62603eeb6f3f@gmail.com> <CALj2ACUJf8ftjiTiNfuVKTvUM3N++dWKnhBOg1EJ29CwoTkXew@mail.gmail.com> <ZR9QJrNJ8lJDZ41P@paquier.xyz> <ZR-pSNRTY2izuNdg@paquier.xyz> <ZR_AESc5tptmpP9t@paquier.xyz> <3365937.1696801735@sss.pgh.pa.us> <ZSPJ0dKz4fdjFs5n@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox