Skip to content

Commit 20335c3

Browse files
startup error propagation (#28)
* startup error propagation * solve CI build issue
1 parent 39c902e commit 20335c3

File tree

9 files changed

+51
-26
lines changed

9 files changed

+51
-26
lines changed

examples/rust/cycle-benchmark/src/activities.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ impl Activity for DummyActivity {
4040
}
4141

4242
#[instrument(name = "Activity startup")]
43-
fn startup(&mut self) {}
43+
fn startup(&mut self) -> Result<(), ActivityError> {
44+
Ok(())
45+
}
4446

4547
#[instrument(name = "Activity step")]
4648
fn step(&mut self) -> Result<(), ActivityError> {

examples/rust/cycle-benchmark/src/composites.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ impl Activity for CompositeActivity {
4949
}
5050

5151
#[instrument(name = "Composite startup")]
52-
fn startup(&mut self) {
52+
fn startup(&mut self) -> Result<(), ActivityError> {
5353
for activity in &mut self.activities {
54-
activity.startup();
54+
activity.startup()?;
5555
}
56+
Ok(())
5657
}
5758

5859
#[instrument(name = "Composite step")]

examples/rust/mini-adas/src/activities/components.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ impl Activity for Camera {
8282
}
8383

8484
#[instrument(name = "Camera startup")]
85-
fn startup(&mut self) {}
85+
fn startup(&mut self) -> Result<(), ActivityError> {
86+
Ok(())
87+
}
8688

8789
#[instrument(name = "Camera")]
8890
fn step(&mut self) -> Result<(), ActivityError> {
@@ -149,7 +151,9 @@ impl Activity for Radar {
149151
}
150152

151153
#[instrument(name = "Radar startup")]
152-
fn startup(&mut self) {}
154+
fn startup(&mut self) -> Result<(), ActivityError> {
155+
Ok(())
156+
}
153157

154158
#[instrument(name = "Radar")]
155159
fn step(&mut self) -> Result<(), ActivityError> {
@@ -236,7 +240,9 @@ impl Activity for NeuralNet {
236240
}
237241

238242
#[instrument(name = "NeuralNet startup")]
239-
fn startup(&mut self) {}
243+
fn startup(&mut self) -> Result<(), ActivityError> {
244+
Ok(())
245+
}
240246

241247
#[instrument(name = "NeuralNet")]
242248
fn step(&mut self) -> Result<(), ActivityError> {
@@ -302,7 +308,9 @@ impl Activity for EmergencyBraking {
302308
}
303309

304310
#[instrument(name = "EmergencyBraking startup")]
305-
fn startup(&mut self) {}
311+
fn startup(&mut self) -> Result<(), ActivityError> {
312+
Ok(())
313+
}
306314

307315
#[instrument(name = "EmergencyBraking")]
308316
fn step(&mut self) -> Result<(), ActivityError> {
@@ -379,7 +387,9 @@ impl Activity for BrakeController {
379387
}
380388

381389
#[instrument(name = "BrakeController startup")]
382-
fn startup(&mut self) {}
390+
fn startup(&mut self) -> Result<(), ActivityError> {
391+
Ok(())
392+
}
383393

384394
#[instrument(name = "BrakeController")]
385395
fn step(&mut self) -> Result<(), ActivityError> {
@@ -435,7 +445,9 @@ impl Activity for EnvironmentRenderer {
435445
}
436446

437447
#[instrument(name = "EnvironmentRenderer startup")]
438-
fn startup(&mut self) {}
448+
fn startup(&mut self) -> Result<(), ActivityError> {
449+
Ok(())
450+
}
439451

440452
#[instrument(name = "EnvironmentRenderer")]
441453
fn step(&mut self) -> Result<(), ActivityError> {
@@ -487,7 +499,9 @@ impl Activity for SteeringController {
487499
}
488500

489501
#[instrument(name = "SteeringController startup")]
490-
fn startup(&mut self) {}
502+
fn startup(&mut self) -> Result<(), ActivityError> {
503+
Ok(())
504+
}
491505

492506
#[instrument(name = "SteeringController")]
493507
fn step(&mut self) -> Result<(), ActivityError> {

feo/src/activity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub trait Activity {
2222
fn id(&self) -> ActivityId;
2323

2424
/// Called upon startup
25-
fn startup(&mut self);
25+
fn startup(&mut self) -> Result<(), ActivityError>;
2626

2727
/// Called upon each step
2828
fn step(&mut self) -> Result<(), ActivityError>;

feo/src/cpp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ macro_rules! cpp_activity {
8686
}
8787

8888
#[instrument(name = "startup")]
89-
fn startup(&mut self) {
89+
fn startup(&mut self) -> Result<(), ActivityError> {
9090
// Safety: Call of external C functions belonging to C++ activitiy, to be reviewed
9191
unsafe { make_fn_call!($name, _startup, (self.cpp_activity)) };
92+
Ok(())
9293
}
9394

9495
#[instrument(name = "step")]

feo/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub enum Error {
4343
#[cfg_attr(feature = "recording", derive(Serialize, Deserialize, MaxSize))]
4444
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4545
pub enum ActivityError {
46+
/// A failure during the `startup()` method.
47+
Startup,
4648
/// A failure during a regular `step()` execution.
4749
Step,
4850
/// A failure during the `shutdown()` method.

feo/src/scheduler.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,11 @@ impl Scheduler {
132132
self.shutdown_gracefully("Startup timeout exceeded.");
133133
return;
134134
}
135-
if self.wait_next_ready().is_err() {
136-
// An error here (like a timeout on receive) can also be a startup failure.
137-
error!(
138-
"Failed to receive ready signal from all activities within startup timeout {:?}.",
139-
self.startup_timeout
140-
);
141-
self.shutdown_gracefully("Failed to receive ready signals during startup.");
135+
if let Err(err) = self.wait_next_ready() {
136+
// An error here, such as ActivityFailed or a timeout, constitutes a startup failure.
137+
// Log the specific error, but pass a generic reason to shutdown_gracefully
138+
error!("A failure occurred during startup: {:?}. Aborting.", err);
139+
self.shutdown_gracefully("Startup failed due to an activity error.");
142140
return;
143141
}
144142
}

feo/src/signalling/common/socket/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,9 @@ impl EncodeDecode for ProtocolSignal {
318318
impl From<u8> for ActivityError {
319319
fn from(value: u8) -> Self {
320320
match value {
321-
0 => ActivityError::Step,
322-
1 => ActivityError::Shutdown,
321+
0 => ActivityError::Startup,
322+
1 => ActivityError::Step,
323+
2 => ActivityError::Shutdown,
323324
_ => panic!("Invalid u8 value for ActivityError"),
324325
}
325326
}
@@ -328,8 +329,9 @@ impl From<u8> for ActivityError {
328329
impl From<ActivityError> for u8 {
329330
fn from(value: ActivityError) -> Self {
330331
match value {
331-
ActivityError::Step => 0,
332-
ActivityError::Shutdown => 1,
332+
ActivityError::Startup => 0,
333+
ActivityError::Step => 1,
334+
ActivityError::Shutdown => 2,
333335
}
334336
}
335337
}

feo/src/worker/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,16 @@ impl<T: ConnectWorker> Worker<T> {
128128

129129
match signal {
130130
Signal::Startup((activity_id, _ts)) => {
131-
activity.startup();
131+
let response_signal = match activity.startup() {
132+
Ok(()) => Signal::Ready((*activity_id, timestamp::timestamp())),
133+
Err(e) => {
134+
error!("Activity {} failed during startup: {:?}", id, e);
135+
Signal::ActivityFailed((*id, e))
136+
}
137+
};
132138
let elapsed = start.elapsed();
133139
debug!("Ran startup of activity {id:?} in {elapsed:?}");
134-
self.connector
135-
.send_to_scheduler(&Signal::Ready((*activity_id, timestamp::timestamp())))
140+
self.connector.send_to_scheduler(&response_signal)
136141
}
137142
Signal::Step((activity_id, _ts)) => {
138143
let response_signal = match activity.step() {

0 commit comments

Comments
 (0)