bytedance / gopkg

Universal Utilities for Go
Apache License 2.0
1.71k stars 224 forks source link

goroutine泄漏 #232

Open denmushi opened 1 month ago

denmushi commented 1 month ago

Operating System

Linux

Go Version

1.20

Package Version

github.com/bytedance/gopkg v0.0.0-20240202110943-5e26950c5e57

Affected Packages

func (c *channel) consume() {
    for {
                // ...
        c.consumer <- it.value // 当外部关闭时,此行有泄漏风险
        atomic.AddUint64(&c.consumed, 1)
    }
}

Expected Behavior

关闭channel时不泄漏

Actual Behavior

关闭channel时会泄漏

Reproduction Steps

  1. c.consumer 被塞满
  2. 消费端不从c.consumer获取数据
  3. 关闭channel
  4. 上述代码处泄漏

Other Information

No response