mailgun / groupcache

Clone of golang/groupcache with TTL and Item Removal support
Apache License 2.0
495 stars 73 forks source link

Deadlock in groupcache lookup #27

Closed workhorse2020 closed 3 years ago

workhorse2020 commented 3 years ago
func main() {
                pool := groupcache.NewHTTPPoolOpts("http://x.x.x.x:8380", &groupcache.HTTPPoolOptions{})
                pool.Set("http://y.y.y.y:8280")
                server := http.Server{
                        Addr:    "localhost:8380",
                        Handler: pool,
                }
                go func() {

When give the sameway to the other people y.y.y.y poolset as x.x.x.x it goes into a deadlock and looking up the db if entry not found. If in y.y.y.y I don;t give Set as x.x.x.x things works fine.

Hence precisely

A-> B B-> A

Above is not valid and we should make sure it doesn't happen this way ?. I mean circular loop ?.

rgds Kamal

thrawn01 commented 3 years ago

Should include self when setting the pool.

pool.Set("http://y.y.y.y:8280", "http://x.x.x.x:8380")
taraspos commented 3 years ago

@thrawn01 I guess the main example from readme has to be update, because there, self is not being added to the pool:

    // Keep track of peers in our cluster and add our instance to the pool `http://localhost:8080`
    pool := groupcache.NewHTTPPoolOpts("http://localhost:8080", &groupcache.HTTPPoolOptions{})

    // Add more peers to the cluster
    pool.Set("http://peer1:8080", "http://peer2:8080")
thrawn01 commented 3 years ago

@Trane9991 done!