Skip to content

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

Closed

Description

@alexandru-savinov

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

Activity

  1. github-actions commented on Oct 20, 2025

    @github-actions
    Contributor

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

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

  2. self-assigned this
    on Oct 20, 2025
  3. rekram1-node commented on Oct 20, 2025

    @rekram1-node
    Collaborator

    will fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions