Skip to content

fix: release port 1455 when OAuth server fails to bind#124

Closed
tryHivemind wants to merge 1 commit into
numman-ali:mainfrom
tryHivemind:fix/oauth-server-port-leak
Closed

fix: release port 1455 when OAuth server fails to bind#124
tryHivemind wants to merge 1 commit into
numman-ali:mainfrom
tryHivemind:fix/oauth-server-port-leak

Conversation

@tryHivemind
Copy link
Copy Markdown

Summary

Fixes #102 — when http.Server emits an error event on .listen() (e.g. EADDRINUSE because another process holds port 1455), the error handler was resolving the promise with ready: false but never calling server.close(). This left the port in a half-open state, so the OS kept it claimed even though we gave up on it. Any subsequent auth attempt would also fail to bind, and the callback URL http://127.0.0.1:1455 would refuse connections.

Root cause in lib/auth/server.ts:

// before
.on("error", (err) => {
    // ...log...
    resolve({ ready: false, close: () => { try { server.close() } catch {} }, ... });
    // port never released here ↑
});

// after
.on("error", (err) => {
    // ...log...
    server.close();   // ← release immediately
    resolve({ ready: false, close: () => { try { server.close() } catch {} }, ... });
});

Test plan

  • Manually occupy port 1455 (nc -l 1455), then run opencode auth login → should fall back to manual paste without hanging
  • Run auth twice in quick succession → second attempt should not get EADDRINUSE from the first

Fixes #102 - when the server errored on listen (e.g. EADDRINUSE),
server.close() was only returned in the close() callback for later
use, but never called immediately. This left the port claimed, causing
subsequent auth attempts to also fail and localhost:1455 to refuse
connections. Added server.close() in the error handler before resolving.
@tryHivemind tryHivemind closed this by deleting the head repository May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] auth return to a url and localhost:1455 refuse to connect

2 participants