[#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:
Alexey Vanin 2025-01-29 19:57:29 +03:00
parent d195cb5104
commit 37350dbb1e

View file

@ -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()
}