golang / groupcache

groupcache is a caching and cache-filling library, intended as a replacement for memcached in many cases.
Apache License 2.0
12.93k stars 1.39k forks source link

bugfix: When the fn function is executed, causing panic will cause the key to remain permanently. This leads to a series of problems. #139

Open liqingqiya opened 4 years ago

liqingqiya commented 4 years ago

When the fn function is executed, causing panic will cause the key to remain permanently. This leads to a series of problems.

goroutine 1

    Group.Do 
        // add 
        g.m[key] = c

        // execute fn()
        c.val, c.err = fn()  // panic;

        // delete key
        delete(g.m, key)

goroutine 2

    Group.Do 
        // lookup  
        if c, ok := g.m[key]; ok {
            g.mu.Unlock()
            c.wg.Wait()         // wait forever
            return