Panic: close of closed channel in status component cleanup #2182

Closed
opened 2026-02-16 17:34:33 -05:00 by yindo · 2 comments
Owner

Originally created by @alexandru-savinov on GitHub (Oct 20, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

OpenCode crashed with a panic during cleanup:

panic: close of closed channel
goroutine 1 [running]:
github.com/sst/opencode/internal/components/status.(*statusComponent).Cleanup(0xc00048e540)
        /home/runner/work/opencode/opencode/packages/tui/internal/components/status/status.go:319 +0x25
github.com/sst/opencode/internal/tui.Model.Cleanup(...)
        /home/runner/work/opencode/opencode/packages/tui/internal/tui/tui.go:948
main.main()
        /home/runner/work/opencode/opencode/packages/tui/cmd/opencode/main.go:166 +0xce9
Terminated

The error occurs in the status component's Cleanup method at line 319, indicating a channel is being closed multiple times.

OpenCode version

0.15.7

Steps to reproduce

  1. Start implementation of a task
  2. Encounter an error during execution
  3. OpenCode attempts cleanup and panics

Root cause

The Cleanup() method is likely being called multiple times without guards against double-close. Possible causes:

  • Missing synchronization (no sync.Once)
  • No check for channel state before closing
  • Multiple cleanup paths calling Cleanup() without re-entry protection

Suggested fix

Implement idempotent cleanup in status.go:319:

// Option 1: sync.Once
var cleanupOnce sync.Once
func (s *statusComponent) Cleanup() {
    cleanupOnce.Do(func() {
        close(s.channel)
    })
}

// Option 2: State tracking
if !s.closed {
    close(s.channel)
    s.closed = true
}

Screenshot and/or share link

No response

Operating System

WSL2 (Windows Subsystem for Linux) running NixOS - Kernel 6.6.87.2-microsoft-standard-WSL2

Terminal

Powershell

Originally created by @alexandru-savinov on GitHub (Oct 20, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description OpenCode crashed with a panic during cleanup: ``` panic: close of closed channel goroutine 1 [running]: github.com/sst/opencode/internal/components/status.(*statusComponent).Cleanup(0xc00048e540) /home/runner/work/opencode/opencode/packages/tui/internal/components/status/status.go:319 +0x25 github.com/sst/opencode/internal/tui.Model.Cleanup(...) /home/runner/work/opencode/opencode/packages/tui/internal/tui/tui.go:948 main.main() /home/runner/work/opencode/opencode/packages/tui/cmd/opencode/main.go:166 +0xce9 Terminated ``` The error occurs in the status component's `Cleanup` method at line 319, indicating a channel is being closed multiple times. ### OpenCode version 0.15.7 ### Steps to reproduce 1. Start implementation of a task 2. Encounter an error during execution 3. OpenCode attempts cleanup and panics ### Root cause The `Cleanup()` method is likely being called multiple times without guards against double-close. Possible causes: - Missing synchronization (no `sync.Once`) - No check for channel state before closing - Multiple cleanup paths calling `Cleanup()` without re-entry protection ### Suggested fix Implement idempotent cleanup in `status.go:319`: ```go // Option 1: sync.Once var cleanupOnce sync.Once func (s *statusComponent) Cleanup() { cleanupOnce.Do(func() { close(s.channel) }) } // Option 2: State tracking if !s.closed { close(s.channel) s.closed = true } ``` ### Screenshot and/or share link _No response_ ### Operating System WSL2 (Windows Subsystem for Linux) running NixOS - Kernel 6.6.87.2-microsoft-standard-WSL2 ### Terminal Powershell
yindo added the bug label 2026-02-16 17:34:33 -05:00
yindo closed this issue 2026-02-16 17:34:33 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 20, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #2999: Same exact panic error "close of closed channel" in status.go:319 during Cleanup() method - reported when pressing Ctrl+C in Windows terminals

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Oct 20, 2025): This issue might be a duplicate of existing issues. Please check: - #2999: Same exact panic error "close of closed channel" in status.go:319 during Cleanup() method - reported when pressing Ctrl+C in Windows terminals Feel free to ignore if none of these address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Oct 20, 2025):

will fix

@rekram1-node commented on GitHub (Oct 20, 2025): will fix
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2182