Skip to content

Comments

Wait for port availability before aborting startup#2304

Open
KristopherKubicki wants to merge 1 commit intostagingfrom
codex/fix-instance-crash-after-adding-camera
Open

Wait for port availability before aborting startup#2304
KristopherKubicki wants to merge 1 commit intostagingfrom
codex/fix-instance-crash-after-adding-camera

Conversation

@KristopherKubicki
Copy link
Owner

Summary

  • add a helper that waits for the configured TCP port to become available
  • wait during startup instead of aborting immediately when the port is briefly in use
  • cover the new helper logic with unit tests for success and timeout paths

Testing

  • flake8
  • pytest
  • pre-commit run --all-files (fails: offline environment cannot download pinned tooling)

Codex Task

Copilot AI review requested due to automatic review settings November 14, 2025 04:21
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 14, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-instance-crash-after-adding-camera

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +407 to +411
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.
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.
"""
Suggested change
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.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

Stale pull request message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant