fix possible deadlock since code can return without unlocking the Mutex

This commit is contained in:
Tobias Wellnitz, DH1TW 2018-01-01 19:57:13 +01:00
parent b0b0338128
commit 0dcea05fb8

View File

@ -182,12 +182,12 @@ func (s *rpcServer) Subscribe(sb Subscriber) error {
}
s.Lock()
defer s.Unlock()
_, ok = s.subscribers[sub]
if ok {
return fmt.Errorf("subscriber %v already exists", s)
}
s.subscribers[sub] = nil
s.Unlock()
return nil
}