Repository navigation
fix(pi-cursor-agent): prevent uncaughtException on socket reset and handle network reconnections - #33
Open
zhangyang-crazy-one wants to merge 1 commit into
Conversation
…andle network reconnections When network connection to api2.cursor.sh is reset or terminated abruptly (e.g., ECONNRESET during TLS handshake or keep-alive teardown), ConnectRPC's Http2SessionManager removes its error listener upon error. The underlying TLS socket and HTTP/2 session then emit secondary error events during destruction in microtasks (onConnectEnd/processTicksAndRejections). Because no listener remains on the EventEmitter, Node/Bun raises an uncaughtException which terminates the host Pi process. Changes: - Add a session-level error guard in AgentService ensuring ClientHttp2Session always retains an error listener to swallow lingering destruction errors. - Pass custom createConnection in nodeOptions to guard underlying TLS and TCP sockets from bubbling unhandled reset errors. - Expand isRetriableError in AgentConnectClient to classify ECONNRESET, socket hang up, and client network disconnection as retriable errors. - Add unit tests verifying socket reset errors are handled gracefully without triggering uncaughtException.
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
Fixes #32.
Prevents
pi-cursor-agentfrom crashing the host Pi process withuncaughtExceptionwhen HTTP/2 socket connections are reset abruptly (ECONNRESET/Client network socket disconnected before secure TLS connection was established). Also enables automatic retry and reconnection on transient connection drops.Changes
AgentService: Installs an error listener guard onhttp2.ClientHttp2Sessionensuring that lingering destruction errors during connection teardown do not escape asuncaughtExceptionafter ConnectRPC'sHttp2SessionManagerdetaches its listener.createConnection: Supplies a guardedcreateConnectionhook innodeOptionsto ensure underlying TLS and TCP sockets have permanent error listeners to absorb unhandled reset events during TLS handshake or teardown.AgentConnectClient: ExtendsisRetriableErrorto recognizeECONNRESET,client network socket disconnected, andsocket hang upas retriable connection errors, enabling exponential backoff reconnection.test/api/agent-service.test.tsverifying that socket resets are handled cleanly without triggeringuncaughtException.Verification
npm run typecheckpassed cleanlynpm run lintpassed without issuesnpm testpassed (36/36 tests passing, including newly added socket reset tests)process.on("uncaughtException").