docker / libkv

Distributed key/value store abstraction library
Apache License 2.0
853 stars 205 forks source link

can not get lock after release. #141

Open xiaoyulei opened 7 years ago

xiaoyulei commented 7 years ago

I write a simple program to test locker. I found locker2 can not get lock after locker1 Unlock.

func main() {                                                                                                                                                                             
        stopChan1 := make(chan struct{})                                                                                                                                                  
        stopChan2 := make(chan struct{})                                                                                                                                                  

        etcd.Register()                                                                                                                                                                   
        s, _ := libkv.NewStore(store.ETCD, []string{"127.0.0.1:2379"}, nil)                                                                                                               
        locker1, _ := s.NewLock("/test", &store.LockOptions{Value: []byte("testvalue"), TTL: 2 * time.Second})                                                                            
        locker2, _ := s.NewLock("/test", &store.LockOptions{Value: []byte("testvalue2"), TTL: 3 * time.Second})                                                                           

        fmt.Println("start lock locker1")                                                                                                                                                 
        locker1.Lock(stopChan1)                                                                                                                                                           
        fmt.Println("get locker1")                                                                                                                                                        

        go func() {                                                                                                                                                                       
                fmt.Println("start lock locker2")                                                                                                                                         
                locker2.Lock(stopChan2)                                                                                                                                                   
                fmt.Println("get locker2")                                                                                                                                                

                locker2.Unlock()                                                                                                                                                          
                fmt.Println("unlock locker2")                                                                                                                                             
        }()                                                                                                                                                                               

        time.Sleep(3 * time.Second)                                                                                                                                                       
        fmt.Println("start unlock locker1")                                                                                                                                               
        locker1.Unlock()                                                                                                                                                                  
        fmt.Println("unlock locker1")                                                                                                                                                     
        time.Sleep(5 * time.Second)                                                                                                                                                       

}                   
get locker1                                                                                 
start lock locker2                                                                          
start unlock locker1                                                                        
unlock locker1
abronan commented 7 years ago

This is fixed in abronan/libkv (I tested with that example)

jlhawn commented 6 years ago

This should be fixed by #186 which includes a test case for this.