go runtime_error ai_generated true

致命错误:所有 goroutine 都处于休眠状态 - 死锁!

fatal error: all goroutines are asleep - deadlock!

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

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

版本兼容性

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

根因分析

一个 goroutine 尝试向无缓冲通道发送数据,但没有接收者,当主 goroutine 也阻塞时导致死锁。

English

A goroutine is blocked trying to send on an unbuffered channel with no receiver, causing a deadlock when the main goroutine also blocks.

generic

解决方案

  1. 95% 成功率
    go func() { ch := make(chan int); go func() { <-ch }(); ch <- 42 }()
  2. 85% 成功率
    select { case ch <- 42: default: }

无效尝试

常见但无效的做法:

  1. 95% 失败

    Sleep doesn't create a receiver; the channel send still blocks indefinitely.

  2. 70% 失败

    If the buffer is full and no receiver, send still blocks after filling buffer.

  3. 90% 失败

    Sending on a closed channel causes a panic, not a deadlock.