Packaged Mac App Silently Failed Port Cleanup Due to Missing /usr/sbin in PATH
A macOS desktop application repeatedly failed to free a occupied network port (8090) because its backend process ran with a restricted PATH that excluded /usr/sbin, the only directory containing the system's lsof binary. As a result, every attempt to reclaim the port silently fell through to a warning branch, meaning the port-freeing code never executed in any shipped build. The bug went undetected during development because terminal sessions inherit a login shell PATH that includes /usr/sbin, making lsof resolve correctly on developers' machines. A secondary finding showed that running lsof without the -sTCP:LISTEN flag also returns connected clients alongside listeners, risking accidental termination of unintended processes. The fix requires resolving system binaries by absolute path first and ensuring fallback log messages expose every path searched, so a permanently-firing warning branch is immediately recognizable as a logic failure rather than an occasional edge case.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in