pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedFree port choosing freezes when PostgresNode::use_tcp is used on BSD systems
6+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2021-04-21 d064afc720 d31ae92866 b931304506 d673905d89 a2eb086042 1d997cb375 Only ever test for non-127.0.0.1 addresses on Windows in PostgresNode
* Free port choosing freezes when PostgresNode::use_tcp is used on BSD systems
@ 2021-04-19 22:22 Alexey Kondratov <a.kondratov@postgrespro.ru>
0 siblings, 1 reply; 6+ messages in thread
From: Alexey Kondratov @ 2021-04-19 22:22 UTC (permalink / raw)
To: pgsql-hackers@lists.postgresql.org
Hi Hackers,
Inside PostgresNode.pm there is a free port choosing routine ---
get_free_port(). The comment section there says:
# On non-Linux, non-Windows kernels, binding to 127.0.0/24 addresses
# other than 127.0.0.1 might fail with EADDRNOTAVAIL.
And this is an absolute true, on BSD-like systems (macOS and FreeBSD
tested) it hangs on looping through the entire ports range over and over
when $PostgresNode::use_tcp = 1 is set, since bind fails with:
# Checking port 52208
# bind: 127.0.0.1 52208
# bind: 127.0.0.2 52208
bind: Can't assign requested address
To reproduce just apply reproduce.diff and try to run 'make -C
src/bin/pg_ctl check'.
This is not a case with standard Postgres tests, since TestLib.pm
chooses unix sockets automatically everywhere outside Windows. However,
we got into this problem when tried to run a custom tap test that
required TCP for stable running.
That way, if it really could happen why not to just skip binding to
127.0.0/24 addresses other than 127.0.0.1 outside of Linux/Windows as
per attached patch_PostgresNode.diff?
Regards
--
Alexey Kondratov
Postgres Professional https://www.postgrespro.com
Russian Postgres Company
Attachments: download all (2 files, .tar.gz)
patch_PostgresNode.diff (text/x-diff, 486B) download
diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm
index db47a97d196..9add9bde2a4 100644
--- a/src/test/perl/PostgresNode.pm
+++ b/src/test/perl/PostgresNode.pm
@@ -1203,7 +1203,7 @@ sub get_free_port
if ($found == 1)
{
foreach my $addr (qw(127.0.0.1),
- $use_tcp ? qw(127.0.0.2 127.0.0.3 0.0.0.0) : ())
+ $use_tcp && ($^O eq "linux" || $TestLib::windows_os) ? qw(127.0.0.2 127.0.0.3 0.0.0.0) : ())
{
if (!can_bind($addr, $port))
{
reproduce.diff (text/x-diff, 467B) download
diff --git a/src/bin/pg_ctl/t/001_start_stop.pl b/src/bin/pg_ctl/t/001_start_stop.pl
index b1e419f02e9..c25c0793537 100644
--- a/src/bin/pg_ctl/t/001_start_stop.pl
+++ b/src/bin/pg_ctl/t/001_start_stop.pl
@@ -11,6 +11,8 @@ use Test::More tests => 24;
my $tempdir = TestLib::tempdir;
my $tempdir_short = TestLib::tempdir_short;
+$PostgresNode::use_tcp = 1;
+
program_help_ok('pg_ctl');
program_version_ok('pg_ctl');
program_options_handling_ok('pg_ctl');
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Free port choosing freezes when PostgresNode::use_tcp is used on BSD systems
@ 2021-04-19 23:22 Tom Lane <tgl@sss.pgh.pa.us>
parent: Alexey Kondratov <a.kondratov@postgrespro.ru>
0 siblings, 1 reply; 6+ messages in thread
From: Tom Lane @ 2021-04-19 23:22 UTC (permalink / raw)
To: Alexey Kondratov <a.kondratov@postgrespro.ru>; +Cc: pgsql-hackers@lists.postgresql.org
Alexey Kondratov <a.kondratov@postgrespro.ru> writes:
> And this is an absolute true, on BSD-like systems (macOS and FreeBSD
> tested) it hangs on looping through the entire ports range over and over
> when $PostgresNode::use_tcp = 1 is set, since bind fails with:
Hm.
> That way, if it really could happen why not to just skip binding to
> 127.0.0/24 addresses other than 127.0.0.1 outside of Linux/Windows as
> per attached patch_PostgresNode.diff?
That patch seems wrong, or at least it's ignoring the advice immediately
above about binding to 0.0.0.0 only on Windows.
I wonder whether we could get away with just replacing the $use_tcp
test with $TestLib::windows_os. It's not really apparent to me
why we should care about 127.0.0.not-1 on Unix-oid systems.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Free port choosing freezes when PostgresNode::use_tcp is used on BSD systems
@ 2021-04-20 14:59 Andrew Dunstan <andrew@dunslane.net>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Dunstan @ 2021-04-20 14:59 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; Alexey Kondratov <a.kondratov@postgrespro.ru>; +Cc: pgsql-hackers@lists.postgresql.org
On 4/19/21 7:22 PM, Tom Lane wrote:
> Alexey Kondratov <a.kondratov@postgrespro.ru> writes:
>> And this is an absolute true, on BSD-like systems (macOS and FreeBSD
>> tested) it hangs on looping through the entire ports range over and over
>> when $PostgresNode::use_tcp = 1 is set, since bind fails with:
> Hm.
>
>> That way, if it really could happen why not to just skip binding to
>> 127.0.0/24 addresses other than 127.0.0.1 outside of Linux/Windows as
>> per attached patch_PostgresNode.diff?
> That patch seems wrong, or at least it's ignoring the advice immediately
> above about binding to 0.0.0.0 only on Windows.
>
> I wonder whether we could get away with just replacing the $use_tcp
> test with $TestLib::windows_os. It's not really apparent to me
> why we should care about 127.0.0.not-1 on Unix-oid systems.
>
>
Yeah
The comment is a bit strange anyway - Cygwin is actually going to use
Unix sockets, not TCP.
I think I would just change the test to this: $use_tcp &&
$TestLib::windows_os.
cheers
andrew
--
Andrew Dunstan
EDB: https://www.enterprisedb.com
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Free port choosing freezes when PostgresNode::use_tcp is used on BSD systems
@ 2021-04-20 15:03 Tom Lane <tgl@sss.pgh.pa.us>
parent: Andrew Dunstan <andrew@dunslane.net>
0 siblings, 1 reply; 6+ messages in thread
From: Tom Lane @ 2021-04-20 15:03 UTC (permalink / raw)
To: Andrew Dunstan <andrew@dunslane.net>; +Cc: Alexey Kondratov <a.kondratov@postgrespro.ru>; pgsql-hackers@lists.postgresql.org
Andrew Dunstan <andrew@dunslane.net> writes:
> On 4/19/21 7:22 PM, Tom Lane wrote:
>> I wonder whether we could get away with just replacing the $use_tcp
>> test with $TestLib::windows_os. It's not really apparent to me
>> why we should care about 127.0.0.not-1 on Unix-oid systems.
> Yeah
> The comment is a bit strange anyway - Cygwin is actually going to use
> Unix sockets, not TCP.
> I think I would just change the test to this: $use_tcp &&
> $TestLib::windows_os.
Works for me, but we need to revise the comment to match.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Free port choosing freezes when PostgresNode::use_tcp is used on BSD systems
@ 2021-04-20 22:49 Alexey Kondratov <a.kondratov@postgrespro.ru>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 6+ messages in thread
From: Alexey Kondratov @ 2021-04-20 22:49 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Andrew Dunstan <andrew@dunslane.net>; pgsql-hackers@lists.postgresql.org
On 2021-04-20 18:03, Tom Lane wrote:
> Andrew Dunstan <andrew@dunslane.net> writes:
>> On 4/19/21 7:22 PM, Tom Lane wrote:
>>> I wonder whether we could get away with just replacing the $use_tcp
>>> test with $TestLib::windows_os. It's not really apparent to me
>>> why we should care about 127.0.0.not-1 on Unix-oid systems.
>
>> Yeah
>> The comment is a bit strange anyway - Cygwin is actually going to use
>> Unix sockets, not TCP.
>> I think I would just change the test to this: $use_tcp &&
>> $TestLib::windows_os.
>
> Works for me, but we need to revise the comment to match.
>
Then it could be somewhat like that, I guess.
Regards
--
Alexey Kondratov
Postgres Professional https://www.postgrespro.com
Russian Postgres Company
Attachments:
PostgresNode.diff (text/x-diff, 1.6K) download
diff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pm
index db47a97d196..f7b488ed464 100644
--- a/src/test/perl/PostgresNode.pm
+++ b/src/test/perl/PostgresNode.pm
@@ -1191,19 +1191,19 @@ sub get_free_port
# Check to see if anything else is listening on this TCP port.
# Seek a port available for all possible listen_addresses values,
# so callers can harness this port for the widest range of purposes.
- # The 0.0.0.0 test achieves that for post-2006 Cygwin, which
- # automatically sets SO_EXCLUSIVEADDRUSE. The same holds for MSYS (a
- # Cygwin fork). Testing 0.0.0.0 is insufficient for Windows native
- # Perl (https://stackoverflow.com/a/14388707), so we also test
- # individual addresses.
+ # The 0.0.0.0 test achieves that for MSYS, which automatically sets
+ # SO_EXCLUSIVEADDRUSE. Testing 0.0.0.0 is insufficient for Windows
+ # native Perl (https://stackoverflow.com/a/14388707), so we also
+ # have to test individual addresses. Doing that for 127.0.0/24
+ # addresses other than 127.0.0.1 might fail with EADDRNOTAVAIL on
+ # non-Linux, non-Windows kernels.
#
- # On non-Linux, non-Windows kernels, binding to 127.0.0/24 addresses
- # other than 127.0.0.1 might fail with EADDRNOTAVAIL. Binding to
- # 0.0.0.0 is unnecessary on non-Windows systems.
+ # That way, 0.0.0.0 and individual 127.0.0/24 addresses are tested
+ # only on Windows when TCP usage is requested.
if ($found == 1)
{
foreach my $addr (qw(127.0.0.1),
- $use_tcp ? qw(127.0.0.2 127.0.0.3 0.0.0.0) : ())
+ $use_tcp && $TestLib::windows_os ? qw(127.0.0.2 127.0.0.3 0.0.0.0) : ())
{
if (!can_bind($addr, $port))
{
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Free port choosing freezes when PostgresNode::use_tcp is used on BSD systems
@ 2021-04-21 14:32 Andrew Dunstan <andrew@dunslane.net>
parent: Alexey Kondratov <a.kondratov@postgrespro.ru>
0 siblings, 0 replies; 6+ messages in thread
From: Andrew Dunstan @ 2021-04-21 14:32 UTC (permalink / raw)
To: Alexey Kondratov <a.kondratov@postgrespro.ru>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers@lists.postgresql.org
On 4/20/21 6:49 PM, Alexey Kondratov wrote:
> On 2021-04-20 18:03, Tom Lane wrote:
>> Andrew Dunstan <andrew@dunslane.net> writes:
>>> On 4/19/21 7:22 PM, Tom Lane wrote:
>>>> I wonder whether we could get away with just replacing the $use_tcp
>>>> test with $TestLib::windows_os. It's not really apparent to me
>>>> why we should care about 127.0.0.not-1 on Unix-oid systems.
>>
>>> Yeah
>>> The comment is a bit strange anyway - Cygwin is actually going to use
>>> Unix sockets, not TCP.
>>> I think I would just change the test to this: $use_tcp &&
>>> $TestLib::windows_os.
>>
>> Works for me, but we need to revise the comment to match.
>>
>
> Then it could be somewhat like that, I guess.
>
>
>
pushed with slight edits.
Thanks.
cheers
andrew
--
Andrew Dunstan
EDB: https://www.enterprisedb.com
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2021-04-21 14:32 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19 22:22 Free port choosing freezes when PostgresNode::use_tcp is used on BSD systems Alexey Kondratov <a.kondratov@postgrespro.ru>
2021-04-19 23:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-04-20 14:59 ` Andrew Dunstan <andrew@dunslane.net>
2021-04-20 15:03 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-04-20 22:49 ` Alexey Kondratov <a.kondratov@postgrespro.ru>
2021-04-21 14:32 ` Andrew Dunstan <andrew@dunslane.net>
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