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

Commit4b4b931

Browse files
committed
Choose ports for test servers less likely to result in conflicts
If we choose ports in the range typically used for ephemeral ports thereis a danger of encountering a port conflict due to a race conditionbetween the time we choose the port in a range below that typically usedto allocate ephemeral ports, but higher than the range typically used bywell known services.Author: Jelte Fenema-Nio, with some editing by me.Discussion:https://postgr.es/m/d6ee8761-39d1-0033-1afb-d5a57ee056f2@gmail.comBackpatch to all live branches (12 and up)
1 parente4f4c54 commit4b4b931

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

‎src/test/perl/PostgreSQL/Test/Cluster.pm

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ our $min_compat = 12;
125125
# list of file reservations made by get_free_port
126126
my@port_reservation_files;
127127

128+
# We want to choose a server port above the range that servers typically use
129+
# on Unix systems and below the range those systems typically use for ephemeral
130+
# client ports.
131+
# That way we minimize the risk of getting a port collision. These two values
132+
# are chosen to reflect that. We will always choose a port in this range.
133+
my$port_lower_bound = 10200;
134+
my$port_upper_bound = 32767;
135+
128136
INIT
129137
{
130138

@@ -149,7 +157,8 @@ INIT
149157
$ENV{PGDATABASE} ='postgres';
150158

151159
# Tracking of last port value assigned to accelerate free port lookup.
152-
$last_port_assigned =int(rand() * 16384) + 49152;
160+
my$num_ports =$port_upper_bound -$port_lower_bound;
161+
$last_port_assigned =int(rand() *$num_ports) +$port_lower_bound;
153162

154163
# Set the port lock directory
155164

@@ -1692,7 +1701,7 @@ sub get_free_port
16921701
{
16931702

16941703
# advance $port, wrapping correctly around range end
1695-
$port =49152if ++$port >= 65536;
1704+
$port =$port_lower_boundif ++$port >$port_upper_bound;
16961705
print"# Checking port$port\n";
16971706

16981707
# Check first that candidate port number is not included in

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp