Skip to content

[Bug] Firecracker cannot shut down successfully without API #4176

Closed
@mkroening

Description

@mkroening

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 #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?

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions