Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4543ef3

Browse files
committed
Test both 0.0.0.0 and 127.0.0.x addresses to find a usable port.
Commitc098509 changedPostgresNode::get_new_node() to probe 0.0.0.0 instead of 127.0.0.1, butthe new test was less effective for Windows native Perl. This increasedthe failure rate of buildfarm members bowerbird and jacana. Instead,test 0.0.0.0 and concrete addresses. This restores the old level ofdefense, but the algorithm is still subject to its longstanding time ofcheck to time of use race condition. Back-patch to 9.6, like theprevious change.Discussion:https://postgr.es/m/GrdLgAdUK9FdyZg8VIcTDKVOkys122ZINEb3CjjoySfGj2KyPiMKTh1zqtRp0TAD7FJ27G-OBB3eplxIB5GhcQH5o8zzGZfp0MuJaXJxVxk=@yesql.se
1 parent2bc0474 commit4543ef3

File tree

1 file changed

+41
-21
lines changed

1 file changed

+41
-21
lines changed

‎src/test/perl/PostgresNode.pm

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -977,27 +977,30 @@ sub get_new_node
977977
$found = 0if ($node->port ==$port);
978978
}
979979

980-
# Check to see if anything else is listening on this TCP port. Accept
981-
# only ports available for all possible listen_addresses values, so
982-
# the caller can harness this port for the widest range of purposes.
983-
# This is *necessary* on Windows, and seems like a good idea on Unixen
984-
# as well, even though we don't ask the postmaster to open a TCP port
985-
# on Unix.
980+
# Check to see if anything else is listening on this TCP port. This
981+
# is *necessary* on $use_tcp (Windows) configurations. Seek a port
982+
# available for all possible listen_addresses values, for own_host
983+
# nodes and so the caller can harness this port for the widest range
984+
# of purposes. The 0.0.0.0 test achieves that for post-2006 Cygwin,
985+
# which automatically sets SO_EXCLUSIVEADDRUSE. The same holds for
986+
# MSYS (a Cygwin fork). Testing 0.0.0.0 is insufficient for Windows
987+
# native Perl (https://stackoverflow.com/a/14388707), so we also test
988+
# individual addresses.
989+
#
990+
# This seems like a good idea on Unixen as well, even though we don't
991+
# ask the postmaster to open a TCP port on Unix. On Non-Linux,
992+
# non-Windows kernels, binding to 127.0.0.1/24 addresses other than
993+
# 127.0.0.1 fails with EADDRNOTAVAIL.
994+
#
995+
# XXX A port available now may become unavailable by the time we start
996+
# the postmaster.
986997
if ($found == 1)
987998
{
988-
my$iaddr = inet_aton('0.0.0.0');
989-
my$paddr = sockaddr_in($port,$iaddr);
990-
my$proto =getprotobyname("tcp");
991-
992-
socket(SOCK, PF_INET, SOCK_STREAM,$proto)
993-
ordie"socket failed:$!";
994-
995-
# As in postmaster, don't use SO_REUSEADDR on Windows
996-
setsockopt(SOCK, SOL_SOCKET, SO_REUSEADDR,pack("l", 1))
997-
unless$TestLib::windows_os;
998-
(bind(SOCK,$paddr) &&listen(SOCK, SOMAXCONN))
999-
or$found = 0;
1000-
close(SOCK);
999+
foreachmy$addr (qw(127.0.0.1 0.0.0.0),
1000+
$use_tcp ?qw(127.0.0.2 127.0.0.3) : ())
1001+
{
1002+
can_bind($addr,$port)or$found = 0;
1003+
}
10011004
}
10021005
}
10031006

@@ -1009,8 +1012,6 @@ sub get_new_node
10091012
{
10101013
if ($use_tcp)
10111014
{
1012-
# This assumes $use_tcp platforms treat every address in
1013-
# 127.0.0.1/24, not just 127.0.0.1, as a usable loopback.
10141015
$last_host_assigned++;
10151016
$last_host_assigned > 254and BAIL_OUT("too many own_host nodes");
10161017
$host ='127.0.0.' .$last_host_assigned;
@@ -1034,6 +1035,25 @@ sub get_new_node
10341035
return$node;
10351036
}
10361037

1038+
# Internal routine to check whether a host:port is available to bind
1039+
subcan_bind
1040+
{
1041+
my ($host,$port) =@_;
1042+
my$iaddr = inet_aton($host);
1043+
my$paddr = sockaddr_in($port,$iaddr);
1044+
my$proto =getprotobyname("tcp");
1045+
1046+
socket(SOCK, PF_INET, SOCK_STREAM,$proto)
1047+
ordie"socket failed:$!";
1048+
1049+
# As in postmaster, don't use SO_REUSEADDR on Windows
1050+
setsockopt(SOCK, SOL_SOCKET, SO_REUSEADDR,pack("l", 1))
1051+
unless$TestLib::windows_os;
1052+
my$ret =bind(SOCK,$paddr) &&listen(SOCK, SOMAXCONN);
1053+
close(SOCK);
1054+
return$ret;
1055+
}
1056+
10371057
# Automatically shut down any still-running nodes when the test script exits.
10381058
# Note that this just stops the postmasters (in the same order the nodes were
10391059
# created in). Temporary PGDATA directories are deleted, in an unspecified

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp