修复潜在的死锁问题:将读锁的作用域限制在块内,避免在持有读锁时尝试获取写锁
This commit is contained in:
parent
6f62d753a5
commit
173814416f
22
src/event.rs
22
src/event.rs
|
|
@ -129,18 +129,19 @@ impl EventManager {
|
|||
.get(&source_id)
|
||||
.and_then(|s| s.client_handle_map.get(&client_handle).copied())
|
||||
};
|
||||
|
||||
if let Some(point_id) = point_id {
|
||||
// 从缓存中读取旧值
|
||||
let monitor_data = connection_manager.get_point_monitor_data_read_guard().await;
|
||||
let old_monitor_info = monitor_data.get(&point_id);
|
||||
let (old_value, old_timestamp, value_changed) = {
|
||||
let monitor_data = connection_manager.get_point_monitor_data_read_guard().await;
|
||||
let old_monitor_info = monitor_data.get(&point_id);
|
||||
|
||||
let (old_value, old_timestamp, value_changed) = if let Some(old_info) = old_monitor_info {
|
||||
let changed = old_info.value != payload.value ||
|
||||
old_info.timestamp != payload.timestamp;
|
||||
(old_info.value.clone(), old_info.timestamp, changed)
|
||||
} else {
|
||||
(None, None, false)
|
||||
if let Some(old_info) = old_monitor_info {
|
||||
let changed = old_info.value != payload.value ||
|
||||
old_info.timestamp != payload.timestamp;
|
||||
(old_info.value.clone(), old_info.timestamp, changed)
|
||||
} else {
|
||||
(None, None, false)
|
||||
}
|
||||
};
|
||||
|
||||
let monitor = crate::telemetry::PointMonitorInfo {
|
||||
|
|
@ -167,7 +168,6 @@ impl EventManager {
|
|||
|
||||
if let Some(ws_manager) = &ws_manager_clone {
|
||||
let ws_message = crate::websocket::WsMessage::PointNewValue(monitor);
|
||||
|
||||
if let Err(e) = ws_manager.send_to_public(ws_message.clone()).await {
|
||||
tracing::error!("Failed to send WebSocket message to public room: {}", e);
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ impl EventManager {
|
|||
if let Err(e) = ws_manager.send_to_client(point_id, ws_message).await {
|
||||
tracing::error!("Failed to send WebSocket message to client room {}: {}", point_id, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tracing::warn!("Point not found for source {} client_handle {}", source_id, client_handle);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue