Skip to content

fix(cli): prevent serve crash when port is free on macOS - #14812

Merged
diegosouzapw merged 3 commits into
diegosouzapw:release/v3.8.51from
prabhtheone:fix/14800-serve-macos-free-port-rebased
Sep 29, 2026
Merged

diegosouzapw merged 3 commits into
diegosouzapw:release/v3.8.51from
prabhtheone:fix/14800-serve-macos-free-port-rebased

Conversation

@prabhtheone

Copy link
Copy Markdown
Contributor

Summary

Fixes #14800.

On macOS, omniroute serve could crash when the requested port was free.
lsof -ti :PORT exits with code 1 and empty output when no process is
listening, which was incorrectly treated as an unavailable discovery result.

This caused the serve preflight to reach a null value and crash when
accessing .length.

Changes

  • Treat lsof exit code 1 with empty output as an empty PID list.
  • Preserve null for genuine port-discovery failures.
  • Use the existing bind-probe fallback when discovery is unavailable.
  • Keep the serve preflight safe when no process is listening.
  • Add regression coverage for the macOS lsof no-match case.

Testing

Added a regression test covering:

  • macOS lsof returning exit code 1 with empty output.
  • Correctly identifying the port as having no listening process.

Related Issue

Closes #14800

@diegosouzapw

Copy link
Copy Markdown
Owner

Thanks for chasing #14800 — the exit-code-1-with-empty-stdout case is the real macOS trigger and your test fails without the fix, passes with it. One more piece is needed though: in bin/cli/commands/serve.mjs (lines ~252–264), when discovery returns null and probePortFree() says the port is free, busyPids stays null and busyPids.length throws — that's the crash from the issue for any host without lsof/netstat too. Could you set busyPids = [] in that branch and add a test at the serve level? Happy to merge right after.

…s null

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
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.

fix(startup): serve crashes on macOS with a free port — "Cannot read properties of null (reading 'length')" (regression from #14538)

2 participants