Hi
When writing my own test, I discovered that when calling the query() method
after the psql session was terminated for some reason, the test script also
terminates prematurely without returning an error. This occurs when calling
pump_until() to get the stderr stream in query()
(detected on Linux, PostgreSQL 16.9).
Here is a simple reproducer:
use strict;
use warnings;
use Carp;
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;
use Config;
my $node = PostgreSQL::Test::Cluster->new('node');
$node->init();
$node->append_conf( 'postgresql.conf', "idle_session_timeout = '0s'" );
$node->append_conf( 'postgresql.conf', "idle_in_transaction_session_timeout =
'1s'" );
$node->start();
my $test->{psql} = $node->background_psql( 'postgres', on_error_stop => 0);
$test->{psql}->query_until(qr//, "begin; select pg_sleep( 3 ); select
'end_of_test';\n");
# Do something
for ( my $i = 0; $i < 3; $i++ ) {
sleep( 1 );
note "Sleep 1 seconds\n";
}
my ($output, $res) = $test->{psql}->query(qq(SELECT 'Is my connection alive?'));
if ($res != 0) {
# Do somthing else
note "Do somthing else\n";
}
$test->{psql}->quit();
$node->stop();
Backtrace:
DB<12> T
@ = DB::DB called from file '/usr/share/perl5/IPC/Run.pm' line 3299
. = IPC::Run::pump_nb(ref(IPC::Run)) called from file
'/src/test/perl/PostgreSQL/Test/Utils.pm' line 432
. = PostgreSQL::Test::Utils::pump_until(ref(IPC::Run), ref(IPC::Run::Timer),
ref(SCALAR), ref(Regexp)) called from file
'/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm' line 272
$ =
PostgreSQL::Test::BackgroundPsql::query(ref(PostgreSQL::Test::BackgroundPsql),
'SELECT \'Is my connection alive?\'') called from file './test.pl' line 24
DB<12> p $@
process ended prematurely at /src/test/perl/PostgreSQL/Test/Utils.pm line 432.
To fix this, it is suggested to add a check for the presence of pumped data
before
the second call to pump_until() in query() to ensure that the psql process is
active.
Thanks for looking.
--
AndreyFrom ddaff0adb9db990c131b854bc04b08f2c1207193 Mon Sep 17 00:00:00 2001
From: Andrey Tsygunka <[email protected]>
Date: Sat, 25 Oct 2025 17:29:40 +0300
Subject: [PATCH] tests: fix an unexpected termination of the test script when
calling 'query()'
When calling the 'query()' method after the psql session was
terminated for some reason, the test script process also
terminates prematurely without returning an error. This
occurs when calling 'pump_until()' to get the stderr stream
in 'query()'.
Added a pumpable check to ensure the psql process is alive.
Fixes: 8b886a4e3488 (tests: BackgroundPsql: Fix potential for lost errors on windows)
Signed-off-by: Andrey Tsygunka <[email protected]>
---
src/test/perl/PostgreSQL/Test/BackgroundPsql.pm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm b/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm
index 60bbd5dd445..efd0945c11f 100644
--- a/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm
+++ b/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm
@@ -272,7 +272,7 @@ sub query
\$self->{stdout}, qr/$banner_match/);
pump_until(
$self->{run}, $self->{timeout},
- \$self->{stderr}, qr/$banner_match/);
+ \$self->{stderr}, qr/$banner_match/) if $self->{run}->pumpable;
die "psql query timed out" if $self->{timeout}->is_expired;
--
2.25.1