Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf483b20

Browse files
committed
worker_spi: Fix another stability issue with BGWORKER_BYPASS_ALLOWCONN
worker_spi_launch() may report that a worker stopped when it fails toconnect on a database that does not allow connections if the workerexits before the SQL function checks for the current status of theworker. The test is switched to use Cluster::psql instead ofsafe_psql() so as it does not fail hard when this query errors. Whileon it, this removes a query that looks at pg_stat_activity to simplifythe test, as a check on the contents of the server logs achieves thesame when the worker cannot connect to the database withoutdatallowconn.Per buildfarm members kestrel, mamba and serinus. Bonus thanks to TomLane for providing the logs of the failure from mamba that the buildfarmwas not able to show up. Note that I have reproduced the failure with ahardcoded stop point.Discussion:https://postgr.es/m/3365937.1696801735@sss.pgh.pa.us
1 parent64aad69 commitf483b20

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

‎src/test/modules/worker_spi/t/001_worker_spi.pl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,30 @@
105105
)ordie"Timed out while waiting for dynamic bgworkers to be launched";
106106

107107
# Check BGWORKER_BYPASS_ALLOWCONN.
108-
$node->safe_psql('postgres',q(ALTER DATABASE mydb ALLOW_CONNECTIONS false;));
108+
$node->safe_psql('postgres',
109+
q(CREATE DATABASE noconndb ALLOW_CONNECTIONS false;));
110+
my$noconndb_id =$node->safe_psql('mydb',
111+
"SELECT oid FROM pg_database where datname = 'noconndb';");
109112
my$log_offset =-s$node->logfile;
110113

111-
# bgworker cannot be launched with connection restriction.
112-
my$worker3_pid =$node->safe_psql('postgres',
113-
qq[SELECT worker_spi_launch(12,$mydb_id,$myrole_id);]);
114+
# worker_spi_launch() may be able to detect that the worker has been
115+
# stopped, so do not rely on psql_safe().
116+
$node->psql('postgres',
117+
qq[SELECT worker_spi_launch(12,$noconndb_id,$myrole_id);]);
114118
$node->wait_for_log(
115-
qr/database "mydb" is not currently accepting connections/,$log_offset);
116-
117-
$result =$node->safe_psql('postgres',
118-
"SELECT count(*) FROM pg_stat_activity WHERE pid =$worker3_pid;");
119-
is($result,'0','dynamic bgworker without BYPASS_ALLOWCONN not started');
119+
qr/database "noconndb" is not currently accepting connections/,
120+
$log_offset);
120121

121122
# bgworker bypasses the connection check, and can be launched.
122123
my$worker4_pid =$node->safe_psql('postgres',
123-
qq[SELECT worker_spi_launch(12,$mydb_id,$myrole_id, '{"ALLOWCONN"}');]);
124+
qq[SELECT worker_spi_launch(12,$noconndb_id,$myrole_id, '{"ALLOWCONN"}');]
125+
);
124126
ok($node->poll_query_until(
125127
'postgres',
126128
qq[SELECT datname, usename, wait_event FROM pg_stat_activity
127129
WHERE backend_type = 'worker_spi dynamic' AND
128130
pid IN ($worker4_pid) ORDER BY datname;],
129-
qq[mydb|myrole|WorkerSpiMain]),
131+
qq[noconndb|myrole|WorkerSpiMain]),
130132
'dynamic bgworker with BYPASS_ALLOWCONN started');
131133

132-
$node->safe_psql('postgres',q(ALTER DATABASE mydb ALLOW_CONNECTIONS true;));
133-
134134
done_testing();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp