firecracker: [Bug] Firecracker cannot shut down successfully without API

Describe the bug

When running Firecracker without API, it prints Error: RunWithoutApiError(Shutdown(Ok)) and returns with a non-zero exit code, although the kernel shut down cleanly, which is also indicated by the error message.

To Reproduce

Launch any kernel without API. This has been tested with Hermit. It should work the same with any other kernel.

  1. Create firecracker-config.json:

    {
      "boot-source": {
        "kernel_image_path": "rusty-loader-x86_64-fc",
        "initrd_path": "hello_world",
        "boot_args": ""
      },
      "drives": [],
      "machine-config": {
        "vcpu_count": 1,
        "mem_size_mib": 256,
        "smt": false
      }
    }
    
  2. Launch Firecracker:

    firecracker --no-api --config-file firecracker-config.json --log-path firecracker.log --level Info --show-level --show-log-origin
    
  3. Compare output and logs from 1.4.1 with 1.5.0:

    • 1.4.1 exit code: 0

    • 1.5.0 exit code: 1

    • 1.4.1 output:

      [kernel messages]
      
    • 1.5.0 output:

      2023-10-15T22:41:46.865613581 [anonymous-instance:main] Running Firecracker v1.5.0
      [kernel messages]
      Error: RunWithoutApiError(Shutdown(Ok))
      
    • 1.4.1 log:

      Running Firecracker v1.4.1
      2023-10-15T22:41:27.341970753 [anonymous-instance:main:INFO:src/vmm/src/device_manager/mmio.rs:393] Artificially kick devices.
      2023-10-15T22:41:27.342026016 [anonymous-instance:main:INFO:src/firecracker/src/main.rs:509] Successfully started microvm that was configured from one single json
      2023-10-15T22:41:27.367335451 [anonymous-instance:fc_vcpu 0:INFO:src/vmm/src/vstate/vcpu/mod.rs:497] Received KVM_EXIT_SHUTDOWN signal
      2023-10-15T22:41:27.367358340 [anonymous-instance:main:INFO:src/vmm/src/lib.rs:842] Vmm is stopping.
      2023-10-15T22:41:27.367426447 [anonymous-instance:main:INFO:src/vmm/src/lib.rs:842] Vmm is stopping.
      
    • 1.5.0 log:

      2023-10-15T22:41:46.865746248 [anonymous-instance:main:INFO:src/vmm/src/logger/logging.rs:93] Running Firecracker v0.1.0
      2023-10-15T22:41:46.876801479 [anonymous-instance:main:INFO:src/vmm/src/device_manager/mmio.rs:392] Artificially kick devices.
      2023-10-15T22:41:46.876843674 [anonymous-instance:main:INFO:src/firecracker/src/main.rs:581] Successfully started microvm that was configured from one single json
      2023-10-15T22:41:46.903474283 [anonymous-instance:fc_vcpu 0:INFO:src/vmm/src/vstate/vcpu/mod.rs:470] Received KVM_EXIT_SHUTDOWN signal
      2023-10-15T22:41:46.903502831 [anonymous-instance:main:INFO:src/vmm/src/lib.rs:806] Vmm is stopping.
      2023-10-15T22:41:46.903586030 [anonymous-instance:main:INFO:src/vmm/src/lib.rs:806] Vmm is stopping.
      2023-10-15T22:41:46.909890194 [anonymous-instance:main:ERROR:src/firecracker/src/main.rs:96] RunWithoutApiError error: MicroVMStopped without an error: Ok
      

Expected behaviour

Return a zero exit code.

Additional context

This is a regression from 1.4.1 to 1.5.0 from 820c5ac from https://github.com/firecracker-microvm/firecracker/pull/3994.

This code is the culprit, as it can never return Ok(()):

    // Run the EventManager that drives everything in the microVM.
    loop {
        event_manager
            .run()
            .expect("Failed to start the event manager");

        if let Some(exit_code) = vmm.lock().unwrap().shutdown_exit_code() {
            return Err(RunWithoutApiError::Shutdown(exit_code));
        }
    }

A fix should be simple. I can open a PR if you like. 😃

Checks

  • Have you searched the Firecracker Issues database for similar problems?
  • Have you read the existing relevant Firecracker documentation?
  • Are you certain the bug being reported is a Firecracker issue?

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Both of those releases work wonderfully (see https://github.com/hermit-os/kernel/pull/1000).

Thanks a lot! 😃

Awesome, thanks a lot! When do you expect 1.5.1 to be released? For now, we downgraded to 1.4.1. 😃

Hi @mkroening, we expect to start working on preparing the 1.5.1 release in two weeks

Thanks! 😃

Thanks for looking into this! 😃