check open ports for which address families we can bind to#5621
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR fixes a critical startup issue on systems without IPv6 support by introducing dynamic address family detection for port checking. Previously, Reflex would fail to start on IPv6-disabled systems because the is_process_on_port() function always attempted to check both IPv4 and IPv6 ports, causing an OSError when trying to create IPv6 sockets on unsupported systems.
The solution adds a new helper function _can_bind_at_any_port() that tests whether a given address family (IPv4 or IPv6) is available for binding by attempting to create and bind a socket. This function gracefully handles exceptions and returns a boolean result. The is_process_on_port() function now accepts an optional address_families parameter, allowing callers to specify which address families to check.
Most importantly, the handle_port() function (which manages port assignment for services) now filters the address families list to only include those that are actually supported by the system before checking port availability. If no address families are available, it provides a clear error message about network configuration issues.
This change integrates seamlessly with the existing process management utilities in processes.py, maintaining backward compatibility while fixing the IPv6-related startup failure. The solution is defensive and handles edge cases like systems with severe network misconfigurations.
Confidence score: 4/5
• This PR is very safe to merge and directly addresses a documented startup failure issue
• The implementation is robust with proper error handling and maintains backward compatibility
• No files need additional review - the changes are well-contained and the logic is sound
1 file reviewed, no comments
CodSpeed Performance ReportMerging #5621 will not alter performanceComparing Summary
|
fixes #5617