mirror of
https://gitee.com/xia-chu/ZLMediaKit.git
synced 2026-05-19 00:07:49 +08:00
bug-fix: rtpserver死锁 (#4421)
Some checks are pending
Android / build (push) Waiting to run
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Docker / build (push) Waiting to run
Linux / build (push) Waiting to run
macOS / build (push) Waiting to run
Windows / build (push) Waiting to run
Some checks are pending
Android / build (push) Waiting to run
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Docker / build (push) Waiting to run
Linux / build (push) Waiting to run
macOS / build (push) Waiting to run
Windows / build (push) Waiting to run
1、RtpServer对应的socket在读取数据后,会加锁后进行数据处理 a) LOCK_GUARD(_mtx_event); b) _on_multi_read 当_on_multi_read处理中出现问题,会通过回调,调用 s_rtp_server.erase(key); , 这里锁的调用顺序为:_mtx_event -> s_rtp_server._mtx 2、当外部调用api关闭RtpServer时,会先调用 s_rtp_server.erase(key); ,释放RtpServer对象时,会调用Socket的 setOnRead(nullptr),这里会调用Socket的 _mtx_event。 这里的锁调用顺序为:s_rtp_server._mtx -> _mtx_event 以上两种情况,存在 交叉调用两把锁的问题,会出现死锁。
This commit is contained in:
parent
41a71f7994
commit
2faa04da30
@ -330,8 +330,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t erase(const std::string &key) {
|
size_t erase(const std::string &key) {
|
||||||
std::lock_guard<std::recursive_mutex> lck(_mtx);
|
Pointer erase_ptr;
|
||||||
return _map.erase(key);
|
{
|
||||||
|
std::lock_guard<std::recursive_mutex> lck(_mtx);
|
||||||
|
auto itr = _map.find(key);
|
||||||
|
if (itr != _map.end()) {
|
||||||
|
erase_ptr = itr->second;
|
||||||
|
_map.erase(itr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size() {
|
size_t size() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user