Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 7 commits into from

Conversation

bagder
Copy link
Member

@bagder bagder commented May 29, 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.

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
tests/servers.pm Outdated Show resolved Hide resolved
Copy link
Contributor

@dfandrich dfandrich left a comment

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
Copy link
Contributor

dfandrich commented May 29, 2023 via email

@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
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.

None yet

2 participants