go runtime_error ai_generated true

致命错误:所有 goroutine 都在休眠 - 死锁!(在通道发送时)

fatal error: all goroutines are asleep - deadlock! (on channel send)

ID: go/goroutine-leak-on-channel-send

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2024-03-15首次发现

版本兼容性

版本状态引入弃用备注
1.21 active
1.22 active

根因分析

一个 goroutine 尝试向没有接收者且没有缓冲的通道发送数据,且没有其他 goroutine 准备好接收,导致程序死锁。

English

A goroutine attempts to send to a channel with no receiver and no buffer, and no other goroutine is ready to receive, causing the program to deadlock.

generic

解决方案

  1. 90% 成功率
    Ensure a receiver goroutine is started before sending, or use a buffered channel with capacity ≥1 if async is acceptable.
  2. 85% 成功率
    Use select with default to make send non-blocking, or use a context with timeout to avoid permanent block.

无效尝试

常见但无效的做法:

  1. 70% 失败

    Buffering may mask the issue temporarily but doesn't solve the fundamental lack of receiver; may cause memory bloat or hidden blocking.

  2. 80% 失败

    Sleeping doesn't guarantee a receiver will appear; it's nondeterministic and may still deadlock or slow the program.