1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-18 05:01:01 +03:00

Make postmaster 003_start_stop.pl test less flaky

The test is very sensitive to how backends start and exit, because it
tests dead-end backends which occur when all the connection slots are
in use. The test failed occasionally in the CI, when the backend that
was launched for the raw_connect_works() check lingered for a while,
and exited only later during the test. When it exited, it released a
connection slot, when the test expected all the slots to be in use at
that time.

The 002_connection_limits.pl test had a similar issue: if the backend
launched for safe_psql() in the test initialization lingers around, it
uses up a connection slot during the test, messing up the test's
connection counting. I haven't seen that in the CI, but when I added a
"sleep(1);" to proc_exit(), the test failed.

To make the tests more robust, restart the server to ensure that the
lingering backends doesn't interfere with the later test steps.

In the passing, fix a bogus test name.

Report and analysis by Jelte Fennema-Nio, Andres Freund, Thomas Munro.

Discussion: https://www.postgresql.org/message-id/CAGECzQSU2iGuocuP+fmu89hmBmR3tb-TNyYKjCcL2M_zTCkAFw@mail.gmail.com
Backpatch-through: 18
This commit is contained in:
Heikki Linnakangas
2025-12-17 16:23:13 +02:00
parent 85ddcc2f4c
commit 5cbaa00592
2 changed files with 11 additions and 1 deletions

View File

@@ -74,6 +74,11 @@ sub connect_fails_wait
ok(1, "$test_name: client backend process exited"); ok(1, "$test_name: client backend process exited");
} }
# Restart the server to ensure that any backends launched for the
# initialization steps are gone. Otherwise they could still be using
# up connection slots and mess with our expectations.
$node->restart;
my @sessions = (); my @sessions = ();
my @raw_connections = (); my @raw_connections = ();

View File

@@ -46,6 +46,11 @@ if (!$node->raw_connect_works())
plan skip_all => "this test requires working raw_connect()"; plan skip_all => "this test requires working raw_connect()";
} }
# Restart the server to ensure that the backend launched for
# raw_connect_works() is gone. Otherwise, it might free up the
# connection slot later, when we expect all the slots to be in use.
$node->restart;
my @raw_connections = (); my @raw_connections = ();
# Open a lot of TCP (or Unix domain socket) connections to use up all # Open a lot of TCP (or Unix domain socket) connections to use up all
@@ -81,7 +86,7 @@ for (my $i = 0; $i <= 20; $i++)
# clients already" instead of "role does not exist" error. Test that # clients already" instead of "role does not exist" error. Test that
# to ensure that we have used up all the slots. # to ensure that we have used up all the slots.
$node->connect_fails("dbname=postgres user=invalid_user", $node->connect_fails("dbname=postgres user=invalid_user",
"connect ", "connection is rejected when all slots are in use",
expected_stderr => qr/FATAL: sorry, too many clients already/); expected_stderr => qr/FATAL: sorry, too many clients already/);
# Open one more connection, to really ensure that we have at least one # Open one more connection, to really ensure that we have at least one