Repository navigation
fix(supervisor): respawn a crashed consumer once, after its backoff #1540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+212
−53
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
53cfd4b
test(supervisor): respawn waits for its backoff and stops after escal…
claude 9cc38d9
fix(supervisor): respawn once per crash, after the backoff
claude 0c8e1d8
docs(supervisor): mark the live-slot check in RespawnG as defensive
claude 576bbb6
test(supervisor): the crash count restarts after a quiet five-minute …
claude dd3ab5d
fix(supervisor): escalate on more than 10 crashes within five minutes
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
crates/lance-graph-supervisor/tests/supervisor_respawn_backoff.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| //! Test: a crashed consumer actor is respawned once per crash, after the | ||
| //! exponential backoff, and not at all once the escalation threshold is passed. | ||
| //! | ||
| //! Issue: ISS-SUPERVISOR-RESPAWN-BACKOFF-NOT-APPLIED. Before the fix, the | ||
| //! `RespawnG` arm respawned at once (no delay) and also scheduled a delayed | ||
| //! `RespawnG { crash_count: 0 }` that re-ran the same arm every 100 ms forever, | ||
| //! so a child escalated past 10 crashes was brought back by that chain. | ||
| //! | ||
| //! Time is paused (`start_paused`), so the 30 s backoff cap costs nothing: | ||
| //! tokio advances the clock whenever every task is idle. | ||
|
|
||
| #[cfg(feature = "supervisor")] | ||
| mod tests { | ||
| use lance_graph_supervisor::{CallcenterSupervisor, ModuleEntry, SupervisorMsg}; | ||
| use ractor::{Actor, ActorRef}; | ||
| use std::time::Duration; | ||
|
|
||
| // The ractor registry is process-global and the tests run in parallel, so | ||
| // each test supervises its own G to keep the child names apart. | ||
| fn one_active_module(g: u32) -> Vec<ModuleEntry> { | ||
| vec![ModuleEntry { | ||
| g, | ||
| version: 1, | ||
| mailbox_capacity: None, | ||
| is_active: true, | ||
| }] | ||
| } | ||
|
|
||
| /// `(is_live, crash_count)` of slot `g` as the supervisor reports it. | ||
| async fn slot(sup: &ActorRef<SupervisorMsg>, g: u32) -> (bool, u32) { | ||
| let health = sup | ||
| .call(|tx| SupervisorMsg::Health { reply: tx }, None) | ||
| .await | ||
| .expect("health call") | ||
| .expect("health reply"); | ||
| let child = health | ||
| .children | ||
| .iter() | ||
| .find(|c| c.g == g) | ||
| .expect("G is in the module table"); | ||
| (child.is_live, child.crash_count) | ||
| } | ||
|
|
||
| fn crash(g: u32) { | ||
| ractor::registry::where_is(format!("consumer_g_{g}")) | ||
| .expect("G is registered while live") | ||
| .stop(None); | ||
| } | ||
|
|
||
| /// Backoff after crash `n`: `min(100 ms * 2^n, 30 s)`. | ||
| fn backoff(n: u32) -> Duration { | ||
| Duration::from_millis((100u64 << n.min(30)).min(30_000)) | ||
| } | ||
|
|
||
| #[tokio::test(start_paused = true)] | ||
| async fn each_crash_respawns_once_after_its_backoff() { | ||
| const G: u32 = 2; | ||
| let (sup, handle) = Actor::spawn(None, CallcenterSupervisor::new(one_active_module(G)), ()) | ||
| .await | ||
| .expect("supervisor spawn"); | ||
| tokio::time::sleep(Duration::from_millis(10)).await; | ||
| assert_eq!(slot(&sup, G).await, (true, 0), "G live before any crash"); | ||
|
|
||
| for n in 1..=2u32 { | ||
| crash(G); | ||
| // Half the backoff: the child must still be down. | ||
| tokio::time::sleep(backoff(n) / 2).await; | ||
| assert!( | ||
| !slot(&sup, G).await.0, | ||
| "crash {n}: respawned before its {:?} backoff", | ||
| backoff(n) | ||
| ); | ||
| // Past the backoff: up again, and the count is carried, not reset. | ||
| tokio::time::sleep(backoff(n)).await; | ||
| assert_eq!( | ||
| slot(&sup, G).await, | ||
| (true, n), | ||
| "crash {n}: one respawn after the backoff" | ||
| ); | ||
| } | ||
|
|
||
| sup.stop(None); | ||
| let _ = handle.await; | ||
| } | ||
|
|
||
| #[tokio::test(start_paused = true)] | ||
| async fn a_child_past_the_escalation_threshold_stays_down() { | ||
| const G: u32 = 3; | ||
| let (sup, handle) = Actor::spawn(None, CallcenterSupervisor::new(one_active_module(G)), ()) | ||
| .await | ||
| .expect("supervisor spawn"); | ||
| tokio::time::sleep(Duration::from_millis(10)).await; | ||
|
|
||
| // Crashes 1..=10 are respawned (threshold is "more than 10"). | ||
| for n in 1..=10u32 { | ||
| crash(G); | ||
| tokio::time::sleep(backoff(n) + Duration::from_millis(50)).await; | ||
| assert_eq!(slot(&sup, G).await, (true, n), "crash {n} is respawned"); | ||
| } | ||
|
|
||
| // Crash 11 escalates: no respawn, however long we wait. | ||
| crash(G); | ||
| tokio::time::sleep(Duration::from_secs(120)).await; | ||
| assert!(!slot(&sup, G).await.0, "crash 11 must not be respawned"); | ||
|
|
||
| sup.stop(None); | ||
| let _ = handle.await; | ||
| } | ||
|
|
||
| /// Spec §5.3: escalation is more than ten crashes within a five-minute | ||
| /// window. A child that ran quietly for longer than the window starts | ||
| /// counting again. | ||
| #[tokio::test(start_paused = true)] | ||
| async fn the_count_restarts_after_a_quiet_window() { | ||
| const G: u32 = 4; | ||
| let (sup, handle) = Actor::spawn(None, CallcenterSupervisor::new(one_active_module(G)), ()) | ||
| .await | ||
| .expect("supervisor spawn"); | ||
| tokio::time::sleep(Duration::from_millis(10)).await; | ||
|
|
||
| for n in 1..=10u32 { | ||
| crash(G); | ||
| tokio::time::sleep(backoff(n) + Duration::from_millis(50)).await; | ||
| assert_eq!(slot(&sup, G).await, (true, n), "crash {n} is respawned"); | ||
| } | ||
|
|
||
| // Six quiet minutes, then one more crash: the count restarts at 1 | ||
| // instead of escalating as crash 11. | ||
| tokio::time::sleep(Duration::from_secs(6 * 60)).await; | ||
| crash(G); | ||
| tokio::time::sleep(backoff(1) + Duration::from_millis(50)).await; | ||
| assert_eq!( | ||
| slot(&sup, G).await, | ||
| (true, 1), | ||
| "a crash after a quiet window counts from 1" | ||
| ); | ||
|
|
||
| sup.stop(None); | ||
| let _ = handle.await; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.