From 7f2d0fbbb29191a235e3bcfeec2d19d62adab619 Mon Sep 17 00:00:00 2001 From: Jarrod Overson Date: Tue, 18 Jul 2023 10:41:18 -0400 Subject: [PATCH] fix: fixed overflow on switch freeze, closes #376 --- .../components/core_component/switch.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/wick/flow-graph-interpreter/src/interpreter/components/core_component/switch.rs b/crates/wick/flow-graph-interpreter/src/interpreter/components/core_component/switch.rs index 76a6ae27..3d3fa26d 100644 --- a/crates/wick/flow-graph-interpreter/src/interpreter/components/core_component/switch.rs +++ b/crates/wick/flow-graph-interpreter/src/interpreter/components/core_component/switch.rs @@ -241,7 +241,7 @@ struct SwitchRouter { conditions: VecDeque, buffer: VecDeque, raw_buffer: VecDeque, - max: Option, + num_conditions: Option, span: Span, } @@ -251,7 +251,7 @@ impl SwitchRouter { conditions: Default::default(), buffer: Default::default(), raw_buffer: Default::default(), - max: None, + num_conditions: None, span, } } @@ -276,10 +276,14 @@ impl SwitchRouter { } fn freeze(&mut self) { - self - .span - .in_scope(|| trace!(conditions = self.conditions.len(), "switch:case: freezing conditions")); - self.max = Some(self.conditions.len() - 1); + self.span.in_scope(|| { + if self.conditions.is_empty() { + debug!("switch:case: match stream done with no conditions set"); + } else { + trace!(conditions = self.conditions.len(), "switch:case: freezing conditions"); + } + }); + self.num_conditions = Some(self.conditions.len()); } fn is_ready(&self, index: usize) -> bool { @@ -297,7 +301,7 @@ impl SwitchRouter { } fn is_frozen(&self) -> bool { - self.max.is_some() + self.num_conditions.is_some() } fn handle_packet(&mut self, index: usize, packet: Packet) {