Wait for port availability before aborting startup#2304
Wait for port availability before aborting startup#2304KristopherKubicki wants to merge 1 commit intostagingfrom
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull Request Overview
This PR improves the application startup behavior by adding a graceful wait mechanism when the configured TCP port is temporarily in use, rather than immediately aborting. The implementation includes a new helper function with configurable timeout and polling interval, along with comprehensive unit tests.
Key Changes
- Added
wait_for_port_to_become_available()helper function with 15-second default timeout and 0.5-second polling interval - Modified startup logic to wait for port availability before aborting, with appropriate logging at each stage
- Added unit tests covering both successful wait and timeout scenarios
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| main.py | Added wait_for_port_to_become_available() helper function and integrated it into the startup flow to wait for port availability instead of immediate abort |
| tests/test_main_utilities.py | Added unit tests for the new wait helper covering success and timeout scenarios with proper mock setup for time and port checking functions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| timeout: Maximum seconds to wait for the port to free. | ||
| interval: Seconds to sleep between checks. | ||
|
|
||
| Returns: | ||
| bool: ``True`` if the port became available within the timeout. |
There was a problem hiding this comment.
[nitpick] The docstring says "Maximum seconds to wait for the port to free" but this doesn't account for the early return when IN_DOCKER is set. Consider clarifying the documentation:
"""Wait for a TCP port to become available.
Args:
port: TCP port to check.
timeout: Maximum seconds to wait for the port to free (ignored in Docker).
interval: Seconds to sleep between checks.
Returns:
bool: ``True`` if the port became available within the timeout,
or if running in Docker. ``False`` if the timeout was reached.
"""| timeout: Maximum seconds to wait for the port to free. | |
| interval: Seconds to sleep between checks. | |
| Returns: | |
| bool: ``True`` if the port became available within the timeout. | |
| timeout: Maximum seconds to wait for the port to free (ignored if running in Docker). | |
| interval: Seconds to sleep between checks. | |
| Returns: | |
| bool: ``True`` if the port became available within the timeout, | |
| or if running in Docker. ``False`` if the timeout was reached. |
|
Stale pull request message |
Summary
Testing
Codex Task