Fix server.close recursion and stale WebSocket ref after close - #194
Open
saiyaangoku64 wants to merge 1 commit into
Open
Fix server.close recursion and stale WebSocket ref after close#194saiyaangoku64 wants to merge 1 commit into
saiyaangoku64 wants to merge 1 commit into
Conversation
createServerWithTools reassigned server.close to a function that called server.close() on itself, causing infinite recursion (or a silent no-op, depending on how the SDK binds the method) instead of calling the original Server.prototype.close. Capture the original close via bind before overriding it. Context.close() also never cleared _ws after closing the socket, so hasWs() continued reporting true for an already-closed connection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
createServerWithToolsinsrc/server.tsreassignsserver.close, but the new implementation callsserver.close()on itself rather than the originalServer.prototype.close. This is self-recursion (infinite loop / stack overflow, or a silent no-op depending on how the SDK binds the method) instead of the intended "close server, then close the websocket server, then close the context" sequence. Fixed by capturing the originalclosevia.bind(server)before overriding.Context.close()insrc/context.tsawaitsthis._ws.close()but never resets_wstoundefinedafterward, sohasWs()keeps returningtruefor a socket that's already closed.Test plan
This repo's
devDependenciesreference privateworkspace:*packages (@repo/config,@repo/messaging,@repo/types,@repo/utils,@r2r/messaging) that only exist in the internal monorepo, sonpm install/npm run build/npm run typecheckcannot be run from a fork (confirmed:npm installfails withEUNSUPPORTEDPROTOCOLon theworkspace:*specifiers, matching the limitation noted in the README).tsc --noEmitdirectly againstsrc/context.tsandsrc/server.tsin isolation; the only errors reported are unresolved-module errors for the@repo/*/@r2r/*workspace packages andnode_modules(expected, since neither exists outside the monorepo) — no syntax or type errors on the changed lines.