Skip to content

Commit 07818d1

Browse files
committed
refactor: improves lock handling and code clarity in session management
Moves lock acquisition for internal maps to after awaiting the dissociate operation to minimize lock contention and potential deadlocks. Refactors error matching for clarity and suppresses a Clippy lint warning to improve code maintainability.
1 parent 416b5f9 commit 07818d1

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

asport-client/src/connection/udp_session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl UdpSession {
262262
return;
263263
}
264264

265-
if let Err(_) = self.0.update.try_send(()) {
265+
if self.0.update.try_send(()).is_err() {
266266
// Mark update as failed and log once
267267
if !self.0.update_failed.swap(true, Ordering::Relaxed) {
268268
log::debug!(

asport-server/src/connection/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ impl Connection {
8080
}
8181
}
8282

83+
#[allow(clippy::too_many_arguments)]
8384
pub async fn handle(
8485
conn: Connecting,
8586
users: Arc<HashMap<Uuid, User>>,

asport-server/src/connection/udp_sessions.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,6 @@ impl UdpSessions {
268268
auth = self.0.conn.auth,
269269
);
270270

271-
let mut addr_map_lock = self.0.assoc_id_addr_map.lock();
272-
let mut activity_lock = self.0.session_last_activity.lock();
273-
274271
for assoc_id in expired_assoc_ids {
275272
// Send dissociate command to client
276273
if let Err(err) = self.0.conn.dissociate(assoc_id).await {
@@ -282,9 +279,13 @@ impl UdpSessions {
282279
);
283280
}
284281

285-
// Remove from internal maps
286-
addr_map_lock.remove_by_left(&assoc_id);
287-
activity_lock.remove(&assoc_id);
282+
// Remove from internal maps after awaiting
283+
{
284+
let mut addr_map_lock = self.0.assoc_id_addr_map.lock();
285+
let mut activity_lock = self.0.session_last_activity.lock();
286+
addr_map_lock.remove_by_left(&assoc_id);
287+
activity_lock.remove(&assoc_id);
288+
}
288289
}
289290
}
290291
}

0 commit comments

Comments
 (0)