Fix port availability check for dual-stack localhost binding #152
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.
Fix port availability check for dual-stack localhost binding
Description
This PR fixes a bug in
_is_port_available()where the server would fail to start withRuntimeError: Could not find an available porteven when ports were actually available.Root Cause
The bug occurred when checking port availability on
localhoston systems with dual-stack networking (IPv4/IPv6):AF_INET(IPv4) andAF_INET6(IPv6) address familiesFalseif any address family failed to bindSolution
Changed the logic to use OR semantics:
Changes Made
lightly_studio/src/lightly_studio/api/server.py:_is_port_available()function to returnTrueon first successful bindlightly_studio/tests/api/test_server.py:test__get_available_port__localhost_with_ipv6_failure()Testing
Manual Testing
Before fix:
RuntimeError: Could not find an available portAfter fix: Server starts successfully on port 8001
Unit Tests
All existing tests pass, plus new test case validates the fix.
Impact
Related Issues
Fixes the issue where users encountered:
Checklist