-
Notifications
You must be signed in to change notification settings - Fork 343
Open
Description
Describe the bug
kvstore/cache_kv.go中很多方法没有使用defer的方式来释放锁,可能会有死锁的风险
To Reproduce
如下代码可能 在获取锁之后若有执行异常则会崩掉,则全局锁则无法释放,造成死锁。

https://github.com/apache/servicecomb-service-center/blob/ce7afe04f5bcad594bede6204a37443bfa9c0a00/datasource/etcd/state/kvstore/cache_kv.go#L45C6-L45C6
| c.rwMux.RUnlock() |
| c.rwMux.RUnlock() |
| c.rwMux.RUnlock() |
| c.rwMux.Unlock() |
| c.rwMux.Unlock() |
| c.rwMux.Unlock() |
Expected behavior
此处预期获取锁之后的执行逻辑无异常,及时把锁释放掉。
为了增强可靠性,可以通过defer的方式来释放锁。
Platform And Runtime (please complete the following information):
Platform
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
Runtime
- Version [e.g. Go 1.11]
Additional context
Add any other context about the problem here.
Metadata
Metadata
Assignees
Labels
No labels