GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||
GeezerVison is showing github.com — opencode serve: Bun collapses every listen() errno to EADDRINUSE, so a bad --hostname is misdiagnosed as a port conflict · Issue #38739 · anomalyco/opencode Closed as not planned Closed as not planned Copy link DescriptionDescriptionUnder Bun, Same script, two runtimes: import { createServer } from "node:http" for (const [host, port] of [["100.68.120.26", 45041], ["127.0.0.1", 80], ["127.0.0.1", 4096]]) { await new Promise((res) => { const s = createServer(() => {}) s.on("error", (e) => { console.log(`${host}:${port} -> ${e.code} ${e.message}`); res() }) s.listen({ host, port }, () => { console.log(`${host}:${port} -> LISTENING`); s.close(); res() }) }) }
Why this matters for opencode
This is a Bun defect, but opencode pins Bun as its runtime, so opencode users hit it and opencode has to defend against it. Proposed fixValidate the address before handing it to import { isIP } from "node:net" import { networkInterfaces } from "node:os" const WILDCARD_HOSTS = new Set(["0.0.0.0", "::", "localhost", "127.0.0.1", "::1"]) /** * Bun's `node:http` shim reports every `listen()` failure as `EADDRINUSE` with the * message "Is port N in use?", so a bad `--hostname` is indistinguishable from a * taken port at the error site. Check the address up front, where we can be exact. */ function assertBindable(opts: ListenOptions) { const hostname = opts.hostname if (WILDCARD_HOSTS.has(hostname)) return // A DNS name is resolved by listen(); only literal IPs can be checked here. if (!isIP(hostname)) return const local = Object.values(networkInterfaces()) .flatMap((entries) => entries ?? []) .map((entry) => entry.address) if (local.includes(hostname)) return throw new Error( `Cannot bind to ${hostname}: it is not an address on any local network interface.` + ` Available: ${[...new Set(local)].join(", ")}.` + ` Use 0.0.0.0 to listen on every interface, or bring the interface up first (e.g. start Tailscale/VPN).`, ) } export async function listen(opts: ListenOptions): Promise<Listener> { assertBindable(opts) ... } Privileged ports can be split off in the if (code === "EADDRINUSE") { if (opts.port !== 0 && opts.port < 1024) return new Error( `Cannot bind ${target}: ports below 1024 are privileged. Use a port >= 1024, or run with elevated privileges.`, { cause: error }, ) return new Error(`Address ${target} is already in use. ...`, { cause: error }) } Verified on
Worth reporting the errno collapsing upstream to oven-sh/bun as well, but opencode should not wait on that fix. PluginsNone. OpenCode version1.17.9 (installed) and 1.18.4 ( Steps to reproduce
Operating SystemmacOS 15.5 (arm64), Bun 1.3.14 TerminalGhostty Activity
MetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions | ||||||||||||||||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |