Skip to content

fix(oauth-callback): clean up socket and server event listeners#1347

Open
walker83 wants to merge 1 commit into
XiaomiMiMo:mainfrom
walker83:fix/oauth-callback-cleanup
Open

fix(oauth-callback): clean up socket and server event listeners#1347
walker83 wants to merge 1 commit into
XiaomiMiMo:mainfrom
walker83:fix/oauth-callback-cleanup

Conversation

@walker83

Copy link
Copy Markdown

Summary

Two listener leaks fixed in oauth-callback.ts.

Leak 1: isPortInUse() socket listeners

socket.on("connect") and socket.on("error") were registered with anonymous lambdas that can never be removed. Extract named handlers and call socket.off() on both paths.

Leak 2: ensureRunning() server error listener

server!.on("error", reject) registers the reject function as a listener but never removes it. Extract a named onError handler and call server.off() on both success and error paths.

Changes

  • packages/opencode/src/mcp/oauth-callback.ts

Checklist

  • Both paths clean up on resolve and reject
  • Backward compatible

Two listener leaks fixed:

1. isPortInUse(): socket 'connect' and 'error' listeners were never removed
   after resolve(). Extract named handlers and call socket.off() in each path.

2. ensureRunning(): server 'error' listener (reject) was registered in the
   listen promise but never removed. Extract named handler and call
   server.off() on both success and error paths.
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.

1 participant