Skip to content

fix(server): silent exit on port conflict — no error logged #21170

Closed as not planned

Description

@sjawhar

Description

When opencode serve --port <N> fails because the port is already in use, the process exits silently with only 3 log lines (version info + config loading). No error is logged — no "port in use", no "EADDRINUSE", no stack trace. The log file and stderr both show nothing beyond config loading.

Expected Behavior

The serve should log an explicit error: Failed to start server: port <N> is already in use (PID <X>) and exit with a non-zero code.

Actual Behavior

Process exits with 3 log lines:

INFO  service=default version=1.3.13-sami.20260406-015434 args=["serve","--port","4096"] opencode
INFO  service=config path=~/.config/opencode/opencode.json loading
INFO  service=config path=~/.config/opencode/opencode.json loading

No error. Exit code 0.

Root Cause

In packages/opencode/src/server/server.ts, tryServe() (line 282-287) catches the Bun.serve() error and returns undefined. Line 290 throws Failed to start server on port ${opts.port} but this may be caught higher up without logging.

const tryServe = (port: number) => {
  try {
    return Bun.serve({ ...args, port })
  } catch {
    return undefined  // swallows the actual error
  }
}

Impact

We hit this three times during fleet deployment (sami-claude, sami, ghost-wispr) — each time a stale serve was holding the port. Debugging took 10-30 minutes each time because there was no error to indicate the port conflict.

Suggested Fix

  1. Log the caught error in tryServe() instead of swallowing it
  2. Check if the port is in use before attempting to bind (e.g. lsof -ti :<port>)
  3. Exit with non-zero code on failure

Environment

  • OpenCode 1.3.13-sami
  • Linux (Ubuntu), Bun 1.3.11

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 6, 2026
  2. github-actions commented on Apr 6, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  3. sjawhar commented on Apr 6, 2026

    @sjawhar
    Author

    Duplicate of #19272. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions