[PATCH] Avoid uninitialized-value error in poll_query_until timeout diagnostic

Started by Bryan Green15 days ago3 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

This thread has been committed, so CI has stopped here. Anything below is the last result it produced.

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t253353
psql -h localhost -U postgres

Built from patchset v1 (message #1), August 11, 2026 at 01:16 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t253353_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t253353_1 && git checkout t253353_1

Patchset v1 (message #1) is on t253353_1

Jump to latest
#1Bryan Green
dbryan.green@gmail.com

Greetings,

PostgreSQL::Test::Cluster::poll_query_until() accepts an undefined query
for connection-only checks -- several recovery TAP tests call it that way:

$node->poll_query_until('postgres', undef, '');

On timeout it builds a diag message that interpolates $query:

diag qq(poll_query_until timed out executing this query:
$query
...);

Cluster.pm runs under "use warnings FATAL => 'all'", so when $query is
undefined this does not warn, it dies with "Use of uninitialized value
$query in concatenation". The result is that a timeout in a connection
only poll fails with an uninitialized-value error instead of printing
the timeout diagnostic the code is trying to produce, hiding the actual
failure.

$ perl -e 'use warnings FATAL => "all"; my $q; my $s = qq(q: $q);'
Use of uninitialized value $q in concatenation (.) or string at -e
line 1.

The fix uses a fallback string when the query is undefined:

my $msg_query = $query // '(undef - connection attempt only)';

and interpolates $msg_query instead. Test-only, one line.

--
Bryan Green
EDB: https://www.enterprisedb.com

Attachments:

t253353_1
0001-Avoid-uninitialized-value-error-in-poll_query_until-.patchtext/plain; charset=UTF-8; name=0001-Avoid-uninitialized-value-error-in-poll_query_until-.patchDownload+2-2
#2Jonathan Gonzalez V.
jonathan.abdiel@gmail.com
In reply to: Bryan Green (#1)
Re: [PATCH] Avoid uninitialized-value error in poll_query_until timeout diagnostic

Hello!!

Bryan Green <dbryan.green@gmail.com> writes:

...
Cluster.pm runs under "use warnings FATAL => 'all'", so when $query is
undefined this does not warn, it dies with "Use of uninitialized value
$query in concatenation". The result is that a timeout in a connection only
poll fails with an uninitialized-value error instead of printing the timeout
diagnostic the code is trying to produce, hiding the actual failure.

$ perl -e 'use warnings FATAL => "all"; my $q; my $s = qq(q: $q);'
Use of uninitialized value $q in concatenation (.) or string at -e line 1.

This was a little bit tricky to reproduce, but I used the following
line:

perl -I src/test/perl -MPostgreSQL::Test::Cluster -MPostgreSQL::Test::Utils -MTest::More -e 'local $PostgreSQL::Test::Utils::timeout_default=0.1; my $n=PostgreSQL::Test::Cluster->new("poll_repro",install_path=>"$ENV{PWD}/build/tmp_install/usr/local/pgsql");ok(!$n->poll_query_until("postgres", undef, ""), "connection-only timeout"); done_testing();'

I wasn't able to reproduce this in a test, so this make sense to happen
only if there's any failure during one of the tests, but this snippet
proved the failure exists.

The fix uses a fallback string when the query is undefined:

my $msg_query = $query // '(undef - connection attempt only)';

and interpolates $msg_query instead. Test-only, one line.

What about using the most common way in the code instead of using `//`
operator? Something like:

my $msg_query = '(undef - connection attempt only)' unless defined $query;

This is how is done everywhere else and is a bit more clear than the
`//` operator which looks pretty tricky even for Perl

Regards,
--
Jonathan Gonzalez V.
EDB
https://www.enterprisedb.com

#3Michael Paquier
michael@paquier.xyz
In reply to: Jonathan Gonzalez V. (#2)
Re: [PATCH] Avoid uninitialized-value error in poll_query_until timeout diagnostic

On Tue, Aug 11, 2026 at 01:32:51PM +0200, Jonathan Gonzalez V. wrote:

What about using the most common way in the code instead of using `//`
operator? Something like:

my $msg_query = '(undef - connection attempt only)' unless defined $query;

This is how is done everywhere else and is a bit more clear than the
`//` operator which looks pretty tricky even for Perl

Using a defined() would be my go-to choice here. Using it in an if()
or an unless does not really matter.

Anyway, will fix one way or the other. Thanks for the report.
--
Michael