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

Strategies added to FreePort for how to pick ports #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JoshuaEngland
Copy link

FreePort was quite inflexible in how it picked ports. If multiple
threads, or processes, were concurrently trying to look for free ports
in a given range there is a high likelihood of collision where they both
think a port is free then race to bind to it.

This change adds strategies for how to pick the ports.

The LinearFreePortStrategy reflects the old strategy of linearly
walking the port range and trying each port.

The RandomizedFreePortStrategy is a new strategy of repeatedly trying
ports in a given range in order to avoid collisions.

This doesn't remove the race condition as theoretically the same
situation can occur with the RandomizedFreePortStrategy as the free port
is never secured. However, it does mitigate against it and reduce the
likelihood of collisions over a big enough range.

FreePort was quite inflexible in how it picked ports. If multiple
threads, or processes, were concurrently trying to look for free ports
in a given range there is a high likelihood of collision where they both
think a port is free then race to bind to it.

This change adds strategies for how to pick the ports.

The LinearFreePortStrategy reflects the old strategy of linearly
walking the port range and trying each port.

The RandomizedFreePortStrategy is a new strategy of repeatedly trying
ports in a given range in order to avoid collisions.

This doesn't remove the race condition as theoretically the same
situation can occur with the RandomizedFreePortStrategy as the free port
is never secured. However, it does mitigate against it and reduce the
likelihood of collisions over a big enough range.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant