Leaked Concurrency Handle (ARCH5085)
هذا المحتوى غير متوفر بلغتك بعد.
Key go.performance.leaked-concurrency-handle · Severity warning · Category performance
Acquiring a Lock without Unlock, or launching a goroutine with no cancellation path, leaks the handle. Guarantee release with defer mu.Unlock().
Incorrect
Section titled “Incorrect”func (c *Cache) Set(k, v string) { c.mu.Lock() if c.closed { return } c.data[k] = v c.mu.Unlock()}Correct
Section titled “Correct”func (c *Cache) Set(k, v string) { c.mu.Lock() defer c.mu.Unlock() if c.closed { return } c.data[k] = v}Release locks with defer mu.Unlock(), and pass a context to goroutines for cancellation.