pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[PATCH] Avoid uninitialized-value error in poll_query_until timeout diagnostic
3+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2026-08-12 6828b03b06 7ff4ee83f7 cfa6884677 1cafef358c 37c4a0730f 1511993de6 d47336e5f6  Fix poll_query_until() timeout handling with an undefined query in Cluster.pm
* [PATCH] Avoid uninitialized-value error in poll_query_until timeout diagnostic
@ 2026-08-09 02:59  Bryan Green <dbryan.green@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Bryan Green @ 2026-08-09 02:59 UTC (permalink / raw)
  To: pgsql-hackers@lists.postgresql.org

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:

0001-Avoid-uninitialized-value-error-in-poll_query_until-.patch (text/plain, 1.5K) download From 114ae6240b1f35c31461228cc2af748bdf8813b9 Mon Sep 17 00:00:00 2001 From: Bryan Green <dbryan.green@gmail.com> Date: Sat, 8 Aug 2026 15:27:42 -0500 Subject: [PATCH] Avoid uninitialized-value error in poll_query_until timeout diagnostic PostgreSQL::Test::Cluster::poll_query_until() accepts an undefined query for connection-only checks; several recovery TAP tests call it as poll_query_until('postgres', undef, ''). On timeout it interpolates $query into the diag message, and because Cluster.pm runs under "use warnings FATAL => 'all'", interpolating the undefined value dies with "Use of uninitialized value" instead of printing the intended diagnostic, hiding the actual timeout. Use a fallback string when the query is undefined. Co-authored-by: Mark Dilger <mark.dilger@enterprisedb.com> --- src/test/perl/PostgreSQL/Test/Cluster.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm index 3eae4cf628..9fec6b4e42 100644 --- a/src/test/perl/PostgreSQL/Test/Cluster.pm +++ b/src/test/perl/PostgreSQL/Test/Cluster.pm @@ -2808,8 +2808,9 @@ sub poll_query_until # Give up. Print the output from the last attempt, hopefully that's useful # for debugging. + my $msg_query = $query // '(undef - connection attempt only)'; diag qq(poll_query_until timed out executing this query: -$query +$msg_query expecting this output: $expected last actual query output: -- 2.49.0
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: [PATCH] Avoid uninitialized-value error in poll_query_until timeout diagnostic
@ 2026-08-11 11:32  Jonathan Gonzalez V. <jonathan.abdiel@gmail.com>
  parent: Bryan Green <dbryan.green@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Jonathan Gonzalez V. @ 2026-08-11 11:32 UTC (permalink / raw)
  To: Bryan Green <dbryan.green@gmail.com>; +Cc: pgsql-hackers@lists.postgresql.org


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






^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [PATCH] Avoid uninitialized-value error in poll_query_until timeout diagnostic
@ 2026-08-12 04:26  Michael Paquier <michael@paquier.xyz>
  parent: Jonathan Gonzalez V. <jonathan.abdiel@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Michael Paquier @ 2026-08-12 04:26 UTC (permalink / raw)
  To: Jonathan Gonzalez V. <jonathan.abdiel@gmail.com>; +Cc: Bryan Green <dbryan.green@gmail.com>; pgsql-hackers@lists.postgresql.org

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

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2026-08-12 04:26 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-09 02:59 [PATCH] Avoid uninitialized-value error in poll_query_until timeout diagnostic Bryan Green <dbryan.green@gmail.com>
2026-08-11 11:32 ` Jonathan Gonzalez V. <jonathan.abdiel@gmail.com>
2026-08-12 04:26   ` Michael Paquier <michael@paquier.xyz>

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