Skip to content

Fix check/use race for port allocation#88

Closed
nhynes wants to merge 1 commit intomainfrom
nhynes/fix-toctou-ports
Closed

Fix check/use race for port allocation#88
nhynes wants to merge 1 commit intomainfrom
nhynes/fix-toctou-ports

Conversation

@nhynes
Copy link
Copy Markdown
Member

@nhynes nhynes commented Mar 26, 2026

No description provided.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3847503e8f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 594 to +597
if reuse_existing && runtime_state_path.is_file() {
let state = read_vm_runtime_state(&runtime_state_path)?;
let (router_listener_reservations, component_reservations_by_id) =
reserve_existing_vm_runtime_ports(runtime_root, vm_plan, &state)?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid reserving live ports in VM launch preview path

materialize_vm_runtime now always calls reserve_existing_vm_runtime_ports when reuse_existing is true, but build_vm_site_launch_preview also calls this code path for read-only preview generation. That means preview commands now try to bind all existing runtime ports and fail with EADDRINUSE whenever the runtime is already running (or any port is occupied), which regresses launch-bundle/inspect flows that should not require taking port ownership.

Useful? React with 👍 / 👎.

Comment on lines +897 to +899
listeners
.outbound_by_export
.insert(binding.export.clone(), listener);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject or track duplicate --export bindings separately

This stores reserved listeners in a map keyed only by binding.export, so repeated --export entries for the same name overwrite earlier reservations. Because export_bindings still keeps both entries, route/listener pairing can become inconsistent (first route may consume the later listener and another route falls back to rebinding), causing unexpected ports or bind failures. Either reject duplicate export names up front or keep reservations keyed per binding instance.

Useful? React with 👍 / 👎.

@nhynes nhynes closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant