Skip to content

Commit 21e4560

Browse files
author
Jonathan Woollett-Light
committed
fix: Refactor error propagation
Refactors error propagation to avoid logging and printing misleading error messages. Signed-off-by: Jonathan Woollett-Light <[email protected]>
1 parent eb292e3 commit 21e4560

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
- Simplified and clarified the removal policy of deprecated API elements
1616
to follow semantic versioning 2.0.0. For more information, please refer to
1717
[this GitHub discussion](https://github.com/firecracker-microvm/firecracker/discussions/4135).
18+
- [#4180](https://github.com/firecracker-microvm/firecracker/pull/4180):
19+
Refactored error propagation to avoid logging and printing an error on
20+
exits with a zero exit code. Now, on successful exit
21+
"Firecracker exited successfully" is logged.
1822

1923
### Deprecated
2024

src/firecracker/src/api_server_adapter.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl ApiServerAdapter {
5252
vm_resources: VmResources,
5353
vmm: Arc<Mutex<Vmm>>,
5454
event_manager: &mut EventManager,
55-
) -> FcExitCode {
55+
) -> Result<(), FcExitCode> {
5656
let api_adapter = Arc::new(Mutex::new(Self {
5757
api_event_fd,
5858
from_api,
@@ -64,10 +64,14 @@ impl ApiServerAdapter {
6464
event_manager
6565
.run()
6666
.expect("EventManager events driver fatal error");
67-
if let Some(exit_code) = vmm.lock().unwrap().shutdown_exit_code() {
68-
return exit_code;
67+
68+
match vmm.lock().unwrap().shutdown_exit_code() {
69+
Some(FcExitCode::Ok) => break,
70+
Some(exit_code) => return Err(exit_code),
71+
None => continue,
6972
}
7073
}
74+
Ok(())
7175
}
7276

7377
fn handle_request(&mut self, req_action: VmmAction) {
@@ -245,7 +249,8 @@ pub(crate) fn run_with_api(
245249
api_thread.join().expect("Api thread should join");
246250

247251
match result {
248-
Ok(exit_code) => Err(ApiServerError::MicroVMStoppedWithoutError(exit_code)),
252+
Ok(Ok(())) => Ok(()),
253+
Ok(Err(exit_code)) => Err(ApiServerError::MicroVMStoppedWithoutError(exit_code)),
249254
Err(exit_error) => Err(exit_error),
250255
}
251256
}

src/firecracker/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ fn main() -> ExitCode {
9898
eprintln!("Error: {err:?}");
9999
ExitCode::from(err)
100100
} else {
101+
info!("Firecracker exited successfully");
101102
ExitCode::SUCCESS
102103
}
103104
}
@@ -631,8 +632,11 @@ fn run_without_api(
631632
.run()
632633
.expect("Failed to start the event manager");
633634

634-
if let Some(exit_code) = vmm.lock().unwrap().shutdown_exit_code() {
635-
return Err(RunWithoutApiError::Shutdown(exit_code));
635+
match vmm.lock().unwrap().shutdown_exit_code() {
636+
Some(FcExitCode::Ok) => break,
637+
Some(exit_code) => return Err(RunWithoutApiError::Shutdown(exit_code)),
638+
None => continue,
636639
}
637640
}
641+
Ok(())
638642
}

tests/integration_tests/functional/test_cmd_line_start.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ def test_config_start_no_api_exit(uvm_plain, vm_config_file):
170170
time.sleep(3) # Wait for shutdown
171171

172172
# Check error log
173-
test_microvm.check_log_message(
174-
"RunWithoutApiError error: MicroVMStopped without an error: Ok"
175-
)
173+
test_microvm.check_log_message("Firecracker exited successfully")
176174

177175

178176
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)