go-runtime 不会将对象推出缓冲通道

go-runtime doesn't push the object out of the buffered channel

我有一个自定义类型(用户定义结构)的缓冲通道。偶尔看到推入频道的对象收不到

在 delve 调试器中 当我打印通道时,我看到 1/100,这意味着通道中存在一个对象。此外,监视此频道的 go 例程是 运行(在 delve 调试器中转储的 go-routines 列表中看到)。 Go-Runtime 是否存在已知问题?

示例代码:-

func sender() {
    myChan := make(chan mystruct, 10)
    myChan <- mystruct
    app.Debug(appctx.LogTagGen, "Posted mystruct to myChan")
}


func goroutinereceiver() {
for {
    select {
    case mystruct := <-myChan:
        funcx(mystruct)
    }
}
}

我可以在日志中看到消息“将 mystruct 发布到 myChan”。此外,在 delve 调试器中,我可以打印此通道以查看通道中存在的对象。另外,我看到接收器 goroutine 是 运行:-

(dlv) print myChan :- myChan {mystruct: chan *mystruct 1/100}

发现问题:- 每当接收 goroutine 在创建通道的 goroutine 之前执行时。接收 go 例程在遇到“nil channel”时将无限期休眠。这就是问题所在。虽然通道是在稍后的时间点创建的,但接收 goroutine 已经处于无限期休眠状态!这个问题并没有始终如一地出现,因为它取决于首先安排哪个 goroutine。