libkv icon indicating copy to clipboard operation
libkv copied to clipboard

can not get lock after release.

Open xiaoyulei opened this issue 9 years ago • 2 comments

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

xiaoyulei avatar Oct 27 '16 08:10 xiaoyulei

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

abronan avatar Aug 28 '17 14:08 abronan

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

jlhawn avatar Dec 19 '17 19:12 jlhawn