From: Alexey Kondratov <a.kondratov@postgrespro.ru>
To: pgsql-hackers@lists.postgresql.org
Subject: Free port choosing freezes when PostgresNode::use_tcp is used on BSD systems
Date: Tue, 20 Apr 2021 01:22:41 +0300
Message-ID: <82e271a9a11928337fcb5b5e57b423c0@postgrespro.ru> (raw)
In-Reply-To: <66bad38beb87fb32952d89602e467444@postgrespro.ru>
References: <20210127213658.GA736@alvherre.pgsql>
<55c6c1526b94d2caf54c33262fe00674@postgrespro.ru>
<e15777decc533006c9dbe4988bd66d31@postgrespro.ru>
<YBTC0IYIGmyYfiIn@paquier.xyz>
<1c506564e2a732ec17790bd8c34f042e@postgrespro.ru>
<YBiro+n0767QDXSA@paquier.xyz>
<YBpEsxZxIVn0zyFM@paquier.xyz>
<66bad38beb87fb32952d89602e467444@postgrespro.ru>
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) downloaddiff --git a/src/test/perl/PostgresNode.pm b/src/test/perl/PostgresNode.pmindex 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) downloaddiff --git a/src/bin/pg_ctl/t/001_start_stop.pl b/src/bin/pg_ctl/t/001_start_stop.plindex 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');
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: a.kondratov@postgrespro.ru, pgsql-hackers@lists.postgresql.org
Subject: Re: Free port choosing freezes when PostgresNode::use_tcp is used on BSD systems
In-Reply-To: <82e271a9a11928337fcb5b5e57b423c0@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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