[fix] fix dead lock during peer init

This commit is contained in:
dijunkun
2025-11-28 09:32:21 +08:00
parent 3d8249bffa
commit 5d9a0a3ea5

View File

@@ -153,6 +153,10 @@ int Render::ConnectTo(const std::string& remote_id, const char* password,
shared_lock.unlock(); shared_lock.unlock();
if (!exists) { if (!exists) {
PeerPtr* peer_to_init = nullptr;
std::string local_id;
{
std::unique_lock unique_lock(client_properties_mutex_); std::unique_lock unique_lock(client_properties_mutex_);
if (client_properties_.find(remote_id) == client_properties_.end()) { if (client_properties_.find(remote_id) == client_properties_.end()) {
client_properties_[remote_id] = client_properties_[remote_id] =
@@ -175,17 +179,18 @@ int Render::ConnectTo(const std::string& remote_id, const char* password,
AddAudioStream(props->peer_, props->audio_label_.c_str()); AddAudioStream(props->peer_, props->audio_label_.c_str());
AddDataStream(props->peer_, props->data_label_.c_str()); AddDataStream(props->peer_, props->data_label_.c_str());
if (props->peer_) { props->connection_status_ = ConnectionStatus::Connecting;
LOG_INFO("[{}] Create peer instance successful", props->local_id_);
Init(props->peer_); peer_to_init = props->peer_;
LOG_INFO("[{}] Peer init finish", props->local_id_); local_id = props->local_id_;
} else { }
LOG_INFO("Create peer [{}] instance failed", props->local_id_);
} }
props->connection_status_ = ConnectionStatus::Connecting; if (peer_to_init) {
LOG_INFO("[{}] Create peer instance successful", local_id);
Init(peer_to_init);
LOG_INFO("[{}] Peer init finish", local_id);
} }
unique_lock.unlock();
} }
int ret = -1; int ret = -1;