Skip to content

tests/servers.pm: pick unused port number with a server socket - #11220

Closed
bagder wants to merge 7 commits into
masterfrom
bagder/tests-servers-getfreeport
Closed

bagder wants to merge 7 commits into
masterfrom
bagder/tests-servers-getfreeport

Conversation

@bagder

@bagder bagder commented May 29, 2023

Copy link
Copy Markdown
Member

This change replaces the previous method of picking a port number at random to try to start servers on, then retrying up to ten times with new random numbers each time, with a function that creates a server socket on port zero, thereby getting a suitable random port set by the kernel. That server socket is then closed and that port number is used to setup the actual test server on.

There is a risk that another server can be started on the machine in the time gap, but the server verification feature will detect that.

This change replaces the previous method of picking a port number at
random to try to start servers on, then retrying up to ten times with
new random numbers each time, with a function that creates a server
socket on port zero, thereby getting a suitable random port set by the
kernel. That server socket is then closed and that port number is used
to setup the actual test server on.

There is a risk that *another* server can be started on the machine in
the time gap, but the server verification feature will detect that.
@bagder bagder added the tests label May 29, 2023
Comment thread tests/servers.pm Resolved

@dfandrich dfandrich left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should definitely help with reliable test server startup, especially in a free port starvation situation. If all the test servers actually start with this PR, then we can assume that they are all already setting SO_REUSEADDR and therefore need no further change to that effect.

Some points that I noticed while reviewing:

  • $serverstartretries can be deleted
  • %usedports can be deleted

@dfandrich

dfandrich commented May 29, 2023 via email

Copy link
Copy Markdown
Contributor

@bagder bagder closed this in 4efa0b5 May 31, 2023
@bagder
bagder deleted the bagder/tests-servers-getfreeport branch May 31, 2023 12:01
bch pushed a commit to bch/curl that referenced this pull request Jul 19, 2023
This change replaces the previous method of picking a port number at
random to try to start servers on, then retrying up to ten times with
new random numbers each time, with a function that creates a server
socket on port zero, thereby getting a suitable random port set by the
kernel. That server socket is then closed and that port number is used
to setup the actual test server on.

There is a risk that *another* server can be started on the machine in
the time gap, but the server verification feature will detect that.

Closes curl#11220
ptitSeb pushed a commit to wasix-org/curl that referenced this pull request Sep 25, 2023
This change replaces the previous method of picking a port number at
random to try to start servers on, then retrying up to ten times with
new random numbers each time, with a function that creates a server
socket on port zero, thereby getting a suitable random port set by the
kernel. That server socket is then closed and that port number is used
to setup the actual test server on.

There is a risk that *another* server can be started on the machine in
the time gap, but the server verification feature will detect that.

Closes curl#11220
samueloph added a commit to Debian/curl that referenced this pull request Mar 9, 2025
 Its usage was dropped at 4efa0b5
 (curl#11220)

 Grepping the tests folder for "portrange" returns only this as a result.
bagder pushed a commit that referenced this pull request Mar 9, 2025
Its usage was dropped at 4efa0b5
(#11220)

Grepping the tests folder for "portrange" returns only this as a result.

Closes #16632
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
Its usage was dropped at 4efa0b5
(curl#11220)

Grepping the tests folder for "portrange" returns only this as a result.

Closes curl#16632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants