fix: skip OS-level port check for addresses outside network namespace #1830
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
When CloudNet runs inside a containerized environment (e.g., Docker with bridge networking) with a host address that doesn't exist in the container's network namespace, the port allocation fails with "No free port found" error. This happens because
NetworkUtil.isInUse()tries to bind aServerSocketto an address that doesn't exist locally, causing all port checks to fail.Modification
NetworkUtil.isBindableAddress()method to check if an address exists in the current network namespaceBaseLocalCloudServiceFactory.isPortInUse()to skip OS-level port validation for external addresses and rely on the CloudNet service registry insteadResult
CloudNet can now correctly allocate ports when running in containerized environments with external host addresses. The service registry is used to prevent port conflicts for addresses outside the local network namespace.