feat: add socket address uniqueness validation for tracker configuration #258
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.
Summary
Implements socket address uniqueness validation for tracker configuration as described in issue #255. This prevents configuration errors where multiple services attempt to bind to the same socket address with the same protocol, which would result in runtime failures.
Changes
Core Implementation
BindingAddress value object (
src/domain/tracker/binding_address.rs)SocketAddrwithProtocolfor type-safe binding representationHashandEqfor HashMap-based duplicate detectionTrackerConfig validation (
src/domain/tracker/config/mod.rs)validate()- Main validation orchestratorcollect_bindings()- Gathers all socket bindings with service namescheck_for_conflicts()- Detects duplicate bindingsregister_binding()/register_trackers()- DRY helper methodsHasBindAddresstrait for generic tracker handlingTrackerConfigError with tiered help system
.help()method for troubleshootingdocs/contributing/error-handling.mdIntegration
TrackerSection.to_tracker_config())CreateConfigErrorValidation Rules
✅ Rejects: Same protocol + same socket address
✅ Allows: Different protocols sharing same port
Manual E2E Testing
Tested with real environment configurations to verify production behavior:
Test Case 1: TCP Conflict ❌ (Correctly Rejected)
Configuration: HTTP Tracker and HTTP API both on
0.0.0.0:7070(TCP){ "http_trackers": [{"bind_address": "0.0.0.0:7070"}], "http_api": {"bind_address": "0.0.0.0:7070", "admin_token": "..."} }Result:
Test Case 2: UDP Conflict ❌ (Correctly Rejected)
Configuration: Two UDP trackers on same address
{ "udp_trackers": [ {"bind_address": "0.0.0.0:6969"}, {"bind_address": "0.0.0.0:6969"} ] }Result:
Test Case 3: Valid Configuration ✅ (Correctly Accepted)
Configuration: All services on unique addresses
{ "udp_trackers": [{"bind_address": "0.0.0.0:6969"}], "http_trackers": [{"bind_address": "0.0.0.0:7070"}], "http_api": {"bind_address": "0.0.0.0:1212"}, "health_check_api": {"bind_address": "127.0.0.1:1313"} }Result: ✅ Environment created successfully
Test Case 4: Cross-Protocol ✅ (Correctly Accepted)
Configuration: UDP and TCP sharing same port (different protocols)
{ "udp_trackers": [{"bind_address": "0.0.0.0:7070"}], "http_trackers": [{"bind_address": "0.0.0.0:7070"}] }Result: ✅ Environment created successfully (UDP and TCP use separate port spaces)
Automated Testing
Code Quality Improvements
This PR includes several refactoring commits that improve code quality:
Benefits:
Documentation
docs/external-issues/tracker/udp-tcp-port-sharing-allowed.mdRelated