fix(app): listen() rejects when the port is taken (#138) #154

Merged
chrnx merged 1 commits from fix/listen-bind-error into develop 2026-10-24 19:17:16 +00:00
Owner

listen() awaited server.listen(port, cb) without an error listener.
A bind failure (EADDRINUSE, EACCES) never calls the callback, so the
promise hung and the error went unhandled. That is the 30 s timeout #138
saw on CI: owner.test.ts reserved a port with freePort() (listen on 0,
close, reuse the number), another process on the shared runner took it,
and the teapot's listen hung instead of failing.

  • core: bind() rejects on the error event. On failure server goes
    back to undefined, so close() resolves and listen() can retry.
  • owner.test.ts: lifetime A listens on port 0 directly, since its teapot
    is up before the teacup needs the port. Lifetime B has to boot its
    teacup against a port nobody holds yet, so it keeps freePort() and
    reruns on a fresh port on EADDRINUSE, up to three times.

Tests: listen on a taken port rejects with EADDRINUSE, then the same app
listens on 0 and serves; close() after a failed listen resolves. Both
hung without the fix.

Closes #138

`listen()` awaited `server.listen(port, cb)` without an `error` listener. A bind failure (EADDRINUSE, EACCES) never calls the callback, so the promise hung and the error went unhandled. That is the 30 s timeout #138 saw on CI: owner.test.ts reserved a port with `freePort()` (listen on 0, close, reuse the number), another process on the shared runner took it, and the teapot's `listen` hung instead of failing. - core: `bind()` rejects on the `error` event. On failure `server` goes back to undefined, so `close()` resolves and `listen()` can retry. - owner.test.ts: lifetime A listens on port 0 directly, since its teapot is up before the teacup needs the port. Lifetime B has to boot its teacup against a port nobody holds yet, so it keeps `freePort()` and reruns on a fresh port on EADDRINUSE, up to three times. Tests: listen on a taken port rejects with EADDRINUSE, then the same app listens on 0 and serves; close() after a failed listen resolves. Both hung without the fix. Closes #138
chrnx added 1 commit 2026-10-24 19:13:43 +00:00
fix(app): listen() rejects when the port is taken (#138)
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 19s
CI / build (pull_request) Successful in 29s
CI / runtimes (edge) (pull_request) Successful in 19s
CI / runtimes (deno) (pull_request) Successful in 33s
bca6fd09eb
`listen()` awaited `server.listen(port, cb)` without an `error` listener.
A bind failure (EADDRINUSE, EACCES) never calls the callback, so the
promise hung and the error went unhandled. That is the 30 s timeout #138
saw on CI: owner.test.ts reserved a port with `freePort()` (listen on 0,
close, reuse the number), another process on the shared runner took it,
and the teapot's `listen` hung instead of failing.

- core: `bind()` rejects on the `error` event. On failure `server` goes
  back to undefined, so `close()` resolves and `listen()` can retry.
- owner.test.ts: lifetime A listens on port 0 directly, since its teapot
  is up before the teacup needs the port. Lifetime B has to boot its
  teacup against a port nobody holds yet, so it keeps `freePort()` and
  reruns on a fresh port on EADDRINUSE, up to three times.

Tests: listen on a taken port rejects with EADDRINUSE, then the same app
listens on 0 and serves; close() after a failed listen resolves. Both
hung without the fix.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx force-pushed fix/listen-bind-error from e09d05028c to bca6fd09eb 2026-10-24 19:13:43 +00:00 Compare
chrnx merged commit 439f37d68f into develop 2026-10-24 19:17:16 +00:00
Sign in to join this conversation.