Mark sessions empty on final client removal
ci / test (push) Waiting to run
ci / fuzz-smoke (push) Waiting to run
ci / windows-client (push) Waiting to run
ci / package-release (linux-x86_64, ubuntu-latest) (push) Waiting to run
ci / package-release (macos-aarch64, macos-14) (push) Waiting to run
ci / package-release (macos-x86_64, macos-13) (push) Waiting to run
ci / package-release (windows-x86_64, windows-latest) (push) Waiting to run
ci / publish-gitea-release (push) Blocked by required conditions
ci / remote-bench (push) Waiting to run
ci / test (push) Waiting to run
ci / fuzz-smoke (push) Waiting to run
ci / windows-client (push) Waiting to run
ci / package-release (linux-x86_64, ubuntu-latest) (push) Waiting to run
ci / package-release (macos-aarch64, macos-14) (push) Waiting to run
ci / package-release (macos-x86_64, macos-13) (push) Waiting to run
ci / package-release (windows-x86_64, windows-latest) (push) Waiting to run
ci / publish-gitea-release (push) Blocked by required conditions
ci / remote-bench (push) Waiting to run
This commit is contained in:
+14
-1
@@ -719,7 +719,11 @@ impl ServerState {
|
||||
if let Some(session_name) = self.client_index.remove(client_id)
|
||||
&& let Some(session) = self.sessions.get_mut(&session_name)
|
||||
{
|
||||
return session.clients.remove(client_id).is_some();
|
||||
let removed = session.clients.remove(client_id).is_some();
|
||||
if removed && session.clients.is_empty() {
|
||||
session.empty_since.get_or_insert_with(Instant::now);
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
false
|
||||
}
|
||||
@@ -4536,6 +4540,15 @@ mod tests {
|
||||
assert!(state.lookup_client(&client_id).is_none());
|
||||
assert!(state.client_mut(&client_id).is_none());
|
||||
assert!(!state.sessions["work"].clients.contains_key(&client_id));
|
||||
assert!(
|
||||
state.sessions["work"].empty_since.is_none(),
|
||||
"removing one of multiple clients must not mark the session empty"
|
||||
);
|
||||
assert!(state.remove_client_everywhere(&[7u8; 16]));
|
||||
assert!(
|
||||
state.sessions["work"].empty_since.is_some(),
|
||||
"removing the final client should start empty-session cleanup grace immediately"
|
||||
);
|
||||
// Removing an absent client is a no-op.
|
||||
assert!(!state.remove_client_everywhere(&client_id));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user