Skip to content

fix(go): close failed session event loops - #2360

Open
green3sf wants to merge 1 commit into
github:mainfrom
green3sf:agent/close-failed-session-event-loop
Open

fix(go): close failed session event loops#2360
green3sf wants to merge 1 commit into
github:mainfrom
green3sf:agent/close-failed-session-event-loop

Conversation

@green3sf

Copy link
Copy Markdown

Summary

  • stop the eagerly started session event consumer when CreateSession fails
  • centralize local event-channel shutdown so failure cleanup does not issue a session.destroy RPC
  • cover RPC errors, malformed responses, session ID mismatches, and SessionFS initialization failures

Root cause

newSession starts processEvents immediately. The affected error paths removed the pre-registered session from Client.sessions but left its event channel open. Because the failed session was neither returned to the caller nor retained for Client.Stop, its goroutine remained blocked on the channel for the lifetime of the process.

The cleanup now removes only the session instance created by the failing call and closes its event channel without making another RPC.

Impact

Failed non-cloud session creation no longer leaks one goroutine, session object, and buffered event channel per attempt.

Validation

  • go test .
  • go test -race . -run 'TestClient_CreateSession(Failure|InitializationFailure)ClosesRegisteredSession' -count=1
  • git diff --check

Fixes #2320

@green3sf
green3sf marked this pull request as ready for review August 19, 2026 12:43
@green3sf
green3sf requested a review from a team as a code owner August 19, 2026 12:43
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.

Go SDK: CreateSession failure leaks the pre-registered session's processEvents goroutine (non-cloud path)

1 participant