[fix] fix crash: ice worker still has IceWorkMsg::Type::Destroy msg which has not been processed when try to stop ice worker

This commit is contained in:
dijunkun
2024-11-27 22:15:45 +08:00
parent 1b7c8905b7
commit 21737c354a
3 changed files with 18 additions and 20 deletions

View File

@@ -7,7 +7,7 @@
#include "log.h" #include "log.h"
#define SAVE_IO_STREAM // #define SAVE_IO_STREAM
IceAgent::IceAgent(bool offer_peer, bool use_trickle_ice, bool use_reliable_ice, IceAgent::IceAgent(bool offer_peer, bool use_trickle_ice, bool use_reliable_ice,
bool enable_turn, bool force_turn, std::string &stun_ip, bool enable_turn, bool force_turn, std::string &stun_ip,

View File

@@ -162,11 +162,10 @@ int PeerConnection::Init(PeerConnectionParams params,
LOG_INFO( LOG_INFO(
"Ice failed, destroy ice agent and rereate it with TURN enabled"); "Ice failed, destroy ice agent and rereate it with TURN enabled");
IceWorkMsg msg; ReleaseAllIceTransmission();
msg.type = IceWorkMsg::Type::Destroy;
PushIceWorkMsg(msg);
if (offer_peer_) { if (offer_peer_) {
IceWorkMsg msg;
msg.type = IceWorkMsg::Type::UserIdList; msg.type = IceWorkMsg::Type::UserIdList;
msg.transmission_id = remote_transmission_id_; msg.transmission_id = remote_transmission_id_;
msg.user_id_list = user_id_list_; msg.user_id_list = user_id_list_;
@@ -277,9 +276,7 @@ int PeerConnection::NegotiationFailed() {
user_id_, remote_user_id_, local_transmission_id_); user_id_, remote_user_id_, local_transmission_id_);
} }
IceWorkMsg msg; ReleaseAllIceTransmission();
msg.type = IceWorkMsg::Type::Destroy;
PushIceWorkMsg(msg);
return 0; return 0;
} }
@@ -302,10 +299,16 @@ int PeerConnection::Leave(const std::string &transmission_id) {
is_ice_transmission_ready_[user_id_] = false; is_ice_transmission_ready_[user_id_] = false;
leave_ = true; leave_ = true;
IceWorkMsg msg; ReleaseAllIceTransmission();
msg.type = IceWorkMsg::Type::Destroy; return 0;
PushIceWorkMsg(msg); }
int PeerConnection::ReleaseAllIceTransmission() {
for (auto &user_id_it : ice_transmission_list_) {
user_id_it.second->DestroyIceTransmission();
}
ice_transmission_list_.clear();
is_ice_transmission_ready_.clear();
return 0; return 0;
} }
@@ -723,14 +726,6 @@ void PeerConnection::ProcessIceWorkMsg(const IceWorkMsg &msg) {
} }
break; break;
} }
case IceWorkMsg::Type::Destroy: {
for (auto &user_id_it : ice_transmission_list_) {
user_id_it.second->DestroyIceTransmission();
}
ice_transmission_list_.clear();
is_ice_transmission_ready_.clear();
break;
}
default: { default: {
break; break;
} }

View File

@@ -68,8 +68,7 @@ struct IceWorkMsg {
UserLeaveTransmission, UserLeaveTransmission,
Offer, Offer,
Answer, Answer,
NewCandidate, NewCandidate
Destroy
}; };
Type type; Type type;
@@ -97,6 +96,8 @@ class PeerConnection {
int Leave(const std::string &transmission_id); int Leave(const std::string &transmission_id);
int ReleaseAllIceTransmission();
int Destroy(); int Destroy();
SignalStatus GetSignalStatus(); SignalStatus GetSignalStatus();
@@ -201,7 +202,9 @@ class PeerConnection {
std::atomic<bool> ice_worker_running_{true}; std::atomic<bool> ice_worker_running_{true};
std::queue<IceWorkMsg> ice_work_msg_queue_; std::queue<IceWorkMsg> ice_work_msg_queue_;
std::condition_variable ice_work_cv_; std::condition_variable ice_work_cv_;
std::condition_variable empty_notify_cv_;
std::mutex ice_work_mutex_; std::mutex ice_work_mutex_;
std::mutex empty_notify_mutex_;
}; };
#endif #endif