BlueGit

ict rusty-teams

fix(calls): an unanswered protocol call blocks the park only for 5 rounds

- page promise that never settles no longer keeps the tab from parking until restart

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-04 · 3 weeks ago

Hash
d109f5c8ec0ff9e16d8aacfdcbf31586a157159c
Parent
3afeb530
2 files changed +25 −7
crates/webview/src/host.rs +1 −1
@@ -615,7 +615,7 @@ extern "system" fn window_procedure(
615 615 let _ = KillTimer(Some(window), PARK_TIMER);
616 616 }
617 617 if let Some(app) = app_of(&shared, window) {
618 let decision = shared.park_gate.borrow().decide(app);
618 let decision = shared.park_gate.borrow_mut().decide(app);
619 619 match decision {
620 620 ParkDecision::Park => park(&shared, app),
621 621 ParkDecision::Wait => unsafe {
@@ -615,7 +615,7 @@ extern "system" fn window_procedure(
615 let _ = KillTimer(Some(window), PARK_TIMER);
615 let _ = KillTimer(Some(window), PARK_TIMER);
616 }
616 }
617 if let Some(app) = app_of(&shared, window) {
617 if let Some(app) = app_of(&shared, window) {
618 let decision = shared.park_gate.borrow().decide(app);
618 let decision = shared.park_gate.borrow_mut().decide(app);
619 match decision {
619 match decision {
620 ParkDecision::Park => park(&shared, app),
620 ParkDecision::Park => park(&shared, app),
621 ParkDecision::Wait => unsafe {
621 ParkDecision::Wait => unsafe {
crates/webview/src/park.rs +24 −6
@@ -2,6 +2,8 @@ use std::collections::HashMap;
2 2
3 3 use session::App;
4 4
5 const MAX_COMMAND_WAITS: usize = 5;
6
5 7 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6 8 pub(crate) enum ParkDecision {
7 9 Park,
@@ -14,6 +16,7 @@ pub(crate) enum ParkDecision {
14 16 pub(crate) struct ParkGate {
15 17 holds: HashMap<App, usize>,
16 18 in_flight: HashMap<App, usize>,
19 command_waits: HashMap<App, usize>,
17 20 }
18 21
19 22 impl ParkGate {
@@ -37,13 +40,18 @@ impl ParkGate {
37 40 self.in_flight.get(&app).copied().unwrap_or(0)
38 41 }
39 42
40 pub(crate) fn decide(&self, app: App) -> ParkDecision {
41 let held = self.holds.get(&app).copied().unwrap_or(0) > 0;
42 if held || self.in_flight(app) > 0 {
43 ParkDecision::Wait
44 } else {
45 ParkDecision::Park
43 /// A protocol call whose page promise never settles stays in flight; after a few waits it no longer blocks the park.
44 pub(crate) fn decide(&mut self, app: App) -> ParkDecision {
45 if self.holds.get(&app).copied().unwrap_or(0) > 0 {
46 return ParkDecision::Wait;
47 }
48 let waits = self.command_waits.entry(app).or_default();
49 if self.in_flight.get(&app).copied().unwrap_or(0) > 0 && *waits < MAX_COMMAND_WAITS {
50 *waits += 1;
51 return ParkDecision::Wait;
46 52 }
53 *waits = 0;
54 ParkDecision::Park
47 55 }
48 56 }
49 57
@@ -71,6 +79,16 @@ mod tests {
71 79 assert_eq!(gate.decide(App::Teams), ParkDecision::Park);
72 80 }
73 81
82 #[test]
83 fn a_command_that_never_answers_stops_blocking_after_a_few_waits() {
84 let mut gate = ParkGate::default();
85 gate.command_started(App::Teams);
86 for _ in 0..MAX_COMMAND_WAITS {
87 assert_eq!(gate.decide(App::Teams), ParkDecision::Wait);
88 }
89 assert_eq!(gate.decide(App::Teams), ParkDecision::Park);
90 }
91
74 92 #[test]
75 93 fn a_held_tab_waits_for_every_hold_to_end() {
76 94 let mut gate = ParkGate::default();
@@ -2,6 +2,8 @@ use std::collections::HashMap;
2
2
3use session::App;
3use session::App;
4
4
5const MAX_COMMAND_WAITS: usize = 5;
6
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub(crate) enum ParkDecision {
8pub(crate) enum ParkDecision {
7 Park,
9 Park,
@@ -14,6 +16,7 @@ pub(crate) enum ParkDecision {
14pub(crate) struct ParkGate {
16pub(crate) struct ParkGate {
15 holds: HashMap<App, usize>,
17 holds: HashMap<App, usize>,
16 in_flight: HashMap<App, usize>,
18 in_flight: HashMap<App, usize>,
19 command_waits: HashMap<App, usize>,
17}
20}
18
21
19impl ParkGate {
22impl ParkGate {
@@ -37,13 +40,18 @@ impl ParkGate {
37 self.in_flight.get(&app).copied().unwrap_or(0)
40 self.in_flight.get(&app).copied().unwrap_or(0)
38 }
41 }
39
42
40 pub(crate) fn decide(&self, app: App) -> ParkDecision {
43 /// A protocol call whose page promise never settles stays in flight; after a few waits it no longer blocks the park.
41 let held = self.holds.get(&app).copied().unwrap_or(0) > 0;
44 pub(crate) fn decide(&mut self, app: App) -> ParkDecision {
42 if held || self.in_flight(app) > 0 {
45 if self.holds.get(&app).copied().unwrap_or(0) > 0 {
43 ParkDecision::Wait
46 return ParkDecision::Wait;
44 } else {
47 }
45 ParkDecision::Park
48 let waits = self.command_waits.entry(app).or_default();
49 if self.in_flight.get(&app).copied().unwrap_or(0) > 0 && *waits < MAX_COMMAND_WAITS {
50 *waits += 1;
51 return ParkDecision::Wait;
46 }
52 }
53 *waits = 0;
54 ParkDecision::Park
47 }
55 }
48}
56}
49
57
@@ -71,6 +79,16 @@ mod tests {
71 assert_eq!(gate.decide(App::Teams), ParkDecision::Park);
79 assert_eq!(gate.decide(App::Teams), ParkDecision::Park);
72 }
80 }
73
81
82 #[test]
83 fn a_command_that_never_answers_stops_blocking_after_a_few_waits() {
84 let mut gate = ParkGate::default();
85 gate.command_started(App::Teams);
86 for _ in 0..MAX_COMMAND_WAITS {
87 assert_eq!(gate.decide(App::Teams), ParkDecision::Wait);
88 }
89 assert_eq!(gate.decide(App::Teams), ParkDecision::Park);
90 }
91
74 #[test]
92 #[test]
75 fn a_held_tab_waits_for_every_hold_to_end() {
93 fn a_held_tab_waits_for_every_hold_to_end() {
76 let mut gate = ParkGate::default();
94 let mut gate = ParkGate::default();