forked from TrueCloudLab/frostfs-sdk-go
[#326] pool: Fix panic that causes mutex deadlock
Two concurrent 'deleteClientFromMap' calls for the same client may produce panic and deadlock. First goroutine acquires lock, removes element from the map, releases lock. Second goroutine acquires lock, and throws panic while trying to call 'close()' on empty struct. Lock is never released and it causes deadlock for other goroutines. Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
parent
d195cb5104
commit
37350dbb1e
1 changed files with 4 additions and 2 deletions
|
@ -1009,8 +1009,10 @@ func (p *Pool) addClientToMap(hash uint64, cl client) {
|
|||
|
||||
func (p *Pool) deleteClientFromMap(hash uint64) {
|
||||
p.mutex.Lock()
|
||||
_ = p.clientMap[hash].close()
|
||||
delete(p.clientMap, hash)
|
||||
if cli, ok := p.clientMap[hash]; ok {
|
||||
_ = cli.close()
|
||||
delete(p.clientMap, hash)
|
||||
}
|
||||
p.mutex.Unlock()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue