mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
fix(appd): keep room for a forced stop behind repeated close requests
Repeated close requests could fill the stop queue, so a forced stop sent after them was dropped while the session was reported as stopping. A close is now queued only into an empty queue, which leaves room for a forced stop.
This commit is contained in:
parent
d509513e0a
commit
d8e9b5a87a
1 changed files with 31 additions and 8 deletions
|
|
@ -125,13 +125,14 @@ impl SessionRegistry {
|
|||
Some(AppStateKind::Stopping)
|
||||
}
|
||||
Some(sender) => {
|
||||
// A full queue already holds a request; a forced one that
|
||||
// does not fit is preceded by one the supervisor acts on.
|
||||
let _ = sender.try_send(if force {
|
||||
runtime::Stop::Force
|
||||
} else {
|
||||
runtime::Stop::Close
|
||||
});
|
||||
// A close is queued only into an empty queue, so a forced
|
||||
// request always finds room; one already queued says the
|
||||
// same as a repeat.
|
||||
if force {
|
||||
let _ = sender.try_send(runtime::Stop::Force);
|
||||
} else if sender.capacity() == runtime::STOP_QUEUE {
|
||||
let _ = sender.try_send(runtime::Stop::Close);
|
||||
}
|
||||
if !force && matches!(state, AppStateKind::Running) {
|
||||
return Some(AppStateKind::Running);
|
||||
}
|
||||
|
|
@ -1814,6 +1815,17 @@ mod tests {
|
|||
while !matches!(rx.recv().await, Ok(Response::AppReady { .. })) {}
|
||||
})
|
||||
.await;
|
||||
// The close is under way: the session is running while it is asked.
|
||||
let asked = dispatch(
|
||||
Request::TerminateApp {
|
||||
session_id,
|
||||
force: false,
|
||||
},
|
||||
®istry,
|
||||
)
|
||||
.await;
|
||||
// Repeats fill no queue a forced stop then cannot enter.
|
||||
for _ in 0..3 {
|
||||
dispatch(
|
||||
Request::TerminateApp {
|
||||
session_id,
|
||||
|
|
@ -1822,6 +1834,7 @@ mod tests {
|
|||
®istry,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
tokio::time::sleep(std::time::Duration::from_millis(300)).await;
|
||||
let forced_at = std::time::Instant::now();
|
||||
let reply = dispatch(
|
||||
|
|
@ -1866,6 +1879,16 @@ mod tests {
|
|||
),
|
||||
"{reply:?}"
|
||||
);
|
||||
assert!(
|
||||
matches!(
|
||||
asked,
|
||||
Response::AppState {
|
||||
state: AppStateKind::Running,
|
||||
..
|
||||
}
|
||||
),
|
||||
"{asked:?}"
|
||||
);
|
||||
assert!(stopped.is_ok(), "the forced stop did not stop the session");
|
||||
// The forced stop does not wait out the close timeout.
|
||||
assert!(elapsed < std::time::Duration::from_secs(3), "{elapsed:?}");
|
||||
|
|
|
|||
Loading…
Reference in a new issue