mirror of
https://github.com/chenhg5/cc-connect.git
synced 2026-07-08 16:12:58 +08:00
In 6 agent session implementations (codex, opencode, qoder, iflow, cursor, gemini), Close() unconditionally calls close(events) after an 8-second timeout, even when the readLoop goroutine may still be running and sending events to the channel. Due to Go's select non-determinism, the readLoop goroutine can choose the send case over the ctx.Done() case, causing a "send on closed channel" panic. Move close(events) into the case where wg.Wait() succeeds (readLoop has fully exited), and skip closing on timeout to prevent the race. This follows the same safe pattern already used by claudeSession, where the events channel is only closed after the readLoop goroutine has finished.