Skip to content

Dev mode: WebChat port 3000 collision crashes the whole process with an uncaught EADDRINUSE exception #27

Description

@medomar

Summary

In dev mode, OpenBridge auto-injects a WebChat connector bound to 0.0.0.0:3000. If port 3000 is already in use (another OpenBridge instance, or a stale tsx watch process tree left over from a previous run), startup throws an uncaught exception and the whole process dies with FATAL ... exiting — instead of failing gracefully or picking a free port.

Environment

  • OpenBridge commit: e366fbe6
  • Node: v22.22.3
  • OS: macOS (darwin, arm64)
  • Config: V2 format, single console channel; WebChat auto-injected by dev mode

Steps to reproduce

  1. Have any process listening on :3000 (e.g. start one npm run dev and leave it running — or have a leaked tsx watch tree from a prior run still holding the port).
  2. Start npm run dev again.
  3. Startup proceeds through AI discovery, config load, Master AI, memory, and the console connector, then the WebChat connector attempts to listen on 3000.

Actual behavior

The process crashes with an uncaught exception:

FATAL (main): Uncaught exception — exiting
    Error: listen EADDRINUSE: address already in use 0.0.0.0:3000
        at Server.setupListenHandle [as _listen2] (node:net:1940:16)
        at listenInCluster (node:net:1997:12)
        at node:net:2206:7
        at process.processTicksAndRejections (node:internal/process/task_queues:89:21)
    code: "EADDRINUSE", errno: -48, syscall: "listen", address: "0.0.0.0", port: 3000

Because all prior initialization (Master AI, MemoryManager, console connector) completes first, the failure happens late in startup and tears down an otherwise-working bridge.

Expected behavior

Either of:

  • Auto-select a free port for WebChat — the AppServer already does exactly this (Port scan complete portStart: 3100 portEnd: 3199), so the WebChat connector could scan/increment from 3000; or
  • Handle the EADDRINUSE listen error gracefully and exit with a clear, actionable message, e.g. "WebChat port 3000 is already in use — set channels[].options.port or stop the other process," rather than letting it bubble to the global uncaught-exception handler.

Notes / suggested fix

  • The dev-mode auto-inject (injectDevConnectors in src/core/config.ts) hardcodes port 3000 with no fallback.
  • The WebChat HTTP server should attach an 'error' handler to its listen() call so EADDRINUSE is caught locally instead of crashing the process.
  • This is most likely to bite when running two instances against two workspaces simultaneously — a supported multi-instance use case — since both auto-inject WebChat on 3000.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions