Merge pull request #224 from dh1tw/rpc-server-subscribe-deadlock
fix possible deadlock since code can return without unlocking the Mutex
This commit is contained in:
commit
45420d8413
@ -182,12 +182,12 @@ func (s *rpcServer) Subscribe(sb Subscriber) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s.Lock()
|
s.Lock()
|
||||||
|
defer s.Unlock()
|
||||||
_, ok = s.subscribers[sub]
|
_, ok = s.subscribers[sub]
|
||||||
if ok {
|
if ok {
|
||||||
return fmt.Errorf("subscriber %v already exists", s)
|
return fmt.Errorf("subscriber %v already exists", s)
|
||||||
}
|
}
|
||||||
s.subscribers[sub] = nil
|
s.subscribers[sub] = nil
|
||||||
s.Unlock()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user