[fix] fix dead lock during connecting

This commit is contained in:
dijunkun
2025-11-28 10:02:57 +08:00
parent 5d9a0a3ea5
commit f6eda34dbd

View File

@@ -79,24 +79,38 @@ int Render::RemoteWindow() {
enter_pressed) { enter_pressed) {
connect_button_pressed_ = true; connect_button_pressed_ = true;
bool found = false; bool found = false;
std::string target_remote_id;
std::string target_password;
bool should_connect = false;
bool already_connected = false;
for (auto& [id, props] : recent_connections_) { for (auto& [id, props] : recent_connections_) {
if (id.find(remote_id) != std::string::npos) { if (id.find(remote_id) != std::string::npos) {
found = true; found = true;
target_remote_id = props.remote_id;
target_password = props.password;
{
std::shared_lock lock(client_properties_mutex_); std::shared_lock lock(client_properties_mutex_);
if (client_properties_.find(remote_id) != if (client_properties_.find(remote_id) !=
client_properties_.end()) { client_properties_.end()) {
if (!client_properties_[remote_id]->connection_established_) { if (!client_properties_[remote_id]->connection_established_) {
ConnectTo(props.remote_id, props.password.c_str(), false); should_connect = true;
} else { } else {
// todo: show warning message already_connected = true;
LOG_INFO("Already connected to [{}]", remote_id);
} }
} else { } else {
ConnectTo(props.remote_id, props.password.c_str(), false); should_connect = true;
}
} }
} }
if (should_connect) {
ConnectTo(target_remote_id, target_password.c_str(), false);
} else if (already_connected) {
LOG_INFO("Already connected to [{}]", remote_id);
}
break;
}
}
if (!found) { if (!found) {
ConnectTo(remote_id, "", false); ConnectTo(remote_id, "", false);
} }