fix: use connection-based port check instead of bind-based
The previous bind-based check (net.createServer + listen) is defeated by SO_REUSEADDR, which Node.js sets by default. On macOS/BSD, SO_REUSEADDR allows two servers to bind to the same port on different addresses (e.g. 127.0.0.1 vs 0.0.0.0) without EADDRINUSE. Switch to a connection-based check (net.Socket.connect) that tries to connect to 127.0.0.1 and ::1 on the target port. If any connection succeeds, something is already listening and the port is considered in use. This correctly detects a Vite server on 127.0.0.1:3000 even though Next.js would bind to [::]:3000.
Showing
Please
register
or
sign in
to comment