Skip to content

Commit

Permalink
Fix #61, 62: very frequent freezing of VM during teardown
Browse files Browse the repository at this point in the history
This will only mitigate the issue and doesn't fix the root cause. The
action doesn't shutdown the VM anymore. Since the action is run
inside a VM itself, everything will be cleaned up automatically.
Hopefully this will make the issue less likely to occur.
  • Loading branch information
jacob-carlborg committed Dec 1, 2023
1 parent 5272ec7 commit 01856ae
Show file tree
Hide file tree
Showing 19 changed files with 151 additions and 21 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -255,6 +255,54 @@ jobs:
hypervisor: qemu
run: dmesg | grep -i avx2

test-no-vm-shutdown:
timeout-minutes: 5
name: Test not shutting down the VM
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Test
uses: ./
with:
operating_system: freebsd
architecture: x86-64
version: '13.2'
hypervisor: qemu
shutdown_vm: false
run: true

- name: Verify VM is still running
run: ps aux | grep -q qemu

test-vm-shutdown:
timeout-minutes: 5
name: Test shutting down the VM
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Test
uses: ./
with:
operating_system: freebsd
architecture: x86-64
version: '13.2'
hypervisor: qemu
shutdown_vm: true
run: true

- name: Verify VM is not running
run: ps aux | grep -q -v qemu

test-sync-files:
timeout-minutes: 5
name: 'Test sync files: ${{ matrix.data.direction }}'
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Expand Up @@ -49,6 +49,11 @@ inputs:
machine and in which direction. Valid values are `true`, `false`,
`runner-to-vm` and `vm-to-runner`.
default: 'true'
shutdown_vm:
required: false
description: |
Specifies if the VM should be shutdown after the action has been run.
default: true

runs:
using: node20
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Added support for specifying that the VM should not shutdown after the action
has run. This adds a new input parameter: `shutdown_vm`. When set to `false`,
this will hopefully mitigate very frequent freezing of VM during teardown ([#61](https://github.com/cross-platform-actions/action/issues/61), [#72](https://github.com/cross-platform-actions/action/issues/72)).

### Changed
- Run any SSH commands to the VM in verbose mode when debug mode is enabled

Expand Down
44 changes: 29 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions readme.md
Expand Up @@ -128,6 +128,7 @@ This section lists the available inputs for the action.
| `hypervisor` || `xhyve` or `qemu` | string | The hypervisor to use for running the virtual machine. For Linux runners the only valid value is `qemu`. For macOS runners the default for OpenBSD and FreeBSD is `xhyve` for all other platforms the default is `qemu`. |
| `image_url` ||| string | URL a custom VM image that should be used in place of the default ones. |
| `sync_files` || `true` | string | Specifies if the local files should be synchronized to the virtual machine and in which direction. Valid values are `true`, `false`, `runner-to-vm` and `vm-to-runner`. `true` synchronizes files in both directions. `false` disables file synchronization. |
| `shutdown_vm` || `true` | boolean | Specifies if the VM should be shutdown after the action has been run. |

All inputs are expected to be of the specified type. It's especially important
that you specify `version` as a string, using single or
Expand Down
6 changes: 6 additions & 0 deletions spec/operating_systems/freebsd/freebsd.spec.ts
Expand Up @@ -9,6 +9,7 @@ import HostQemu from '../../../src/host_qemu'
import * as hypervisor from '../../../src/hypervisor'
import * as qemu from '../../../src/qemu_vm'
import * as xhyve from '../../../src/xhyve_vm'
import {Input} from '../../../src/action/input'

describe('FreeBSD OperatingSystem', () => {
class MockHost extends hostModule.Host {
Expand Down Expand Up @@ -47,6 +48,7 @@ describe('FreeBSD OperatingSystem', () => {
let hypervisorDirectory = 'hypervisor/directory'
let resourcesDirectory = 'resources/directory'
let firmwareDirectory = 'firmware/directory'
let input = new Input()

let config = {
memory: '4G',
Expand All @@ -70,13 +72,15 @@ describe('FreeBSD OperatingSystem', () => {
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
input,
config
)

expect(vmModule).toHaveBeenCalledOnceWith(
hypervisorDirectory,
resourcesDirectory,
architecture,
input,
{
...config,
ssHostPort: 2847,
Expand All @@ -102,6 +106,7 @@ describe('FreeBSD OperatingSystem', () => {
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
input,
config
)

Expand All @@ -123,6 +128,7 @@ describe('FreeBSD OperatingSystem', () => {
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
input,
config
)

Expand Down
4 changes: 3 additions & 1 deletion spec/operating_systems/freebsd/qemu_vm.spec.ts
Expand Up @@ -4,6 +4,7 @@ import {host} from '../../../src/host'
import * as os from '../../../src/operating_systems/kind'
import {Accelerator} from '../../../src/vm'
import '../../../src/operating_systems/freebsd/freebsd'
import {Input} from '../../../src/action/input'

describe('FreeBSD QemuVm', () => {
let memory = '5G'
Expand All @@ -17,6 +18,7 @@ describe('FreeBSD QemuVm', () => {
osKind,
host.hypervisor
)
let input = new Input()
let config = {
memory: memory,
cpuCount: cpuCount,
Expand All @@ -30,7 +32,7 @@ describe('FreeBSD QemuVm', () => {
userboot: '',
firmware: ''
}
let vm = new QemuVm('', '', architecture, config)
let vm = new QemuVm('', '', architecture, input, config)

let getFlagValue = (flag: string) => vm.command[vm.command.indexOf(flag) + 1]
let actualMemory = () => getFlagValue('-m')
Expand Down
6 changes: 6 additions & 0 deletions spec/operating_systems/netbsd/netbsd.spec.ts
Expand Up @@ -8,6 +8,7 @@ import * as hypervisor from '../../../src/hypervisor'
import * as qemu from '../../../src/qemu_vm'
import * as xhyve from '../../../src/xhyve_vm'
import * as netbsdQemuVm from '../../../src/operating_systems/netbsd/qemu_vm'
import {Input} from '../../../src/action/input'

describe('NetBSD OperatingSystem', () => {
class Host extends hostModule.Host {
Expand Down Expand Up @@ -50,6 +51,7 @@ describe('NetBSD OperatingSystem', () => {
let hypervisorDirectory = 'hypervisor/directory'
let resourcesDirectory = 'resources/directory'
let firmwareDirectory = 'firmware/directory'
let input = new Input()

let config = {
memory: '4G',
Expand All @@ -67,13 +69,15 @@ describe('NetBSD OperatingSystem', () => {
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
input,
config
)

expect(qemuVmSpy).toHaveBeenCalledOnceWith(
hypervisorDirectory,
resourcesDirectory,
architecture,
input,
{
...config,
ssHostPort: 2847,
Expand Down Expand Up @@ -133,13 +137,15 @@ describe('NetBSD OperatingSystem', () => {
hypervisorDirectory,
resourcesDirectory,
firmwareDirectory,
input,
config
)

expect(qemuVmSpy).toHaveBeenCalledOnceWith(
hypervisorDirectory,
resourcesDirectory,
architecture,
input,
{
...config,
ssHostPort: 2847,
Expand Down
4 changes: 3 additions & 1 deletion spec/operating_systems/netbsd/qemu_vm.spec.ts
Expand Up @@ -4,6 +4,7 @@ import {host} from '../../../src/host'
import * as os from '../../../src/operating_systems/kind'
import {Accelerator} from '../../../src/vm'
import '../../../src/operating_systems/netbsd/netbsd'
import {Input} from '../../../src/action/input'

describe('NetBSD QemuVm', () => {
let memory = '5G'
Expand All @@ -17,6 +18,7 @@ describe('NetBSD QemuVm', () => {
osKind,
host.hypervisor
)
let input = new Input()
let config = {
memory: memory,
cpuCount: cpuCount,
Expand All @@ -30,7 +32,7 @@ describe('NetBSD QemuVm', () => {
userboot: '',
firmware: ''
}
let vm = new Vm('', '', architecture, config)
let vm = new Vm('', '', architecture, input, config)

let getFlagValue = (flag: string) => vm.command[vm.command.indexOf(flag) + 1]
let actualMemory = () => getFlagValue('-m')
Expand Down

0 comments on commit 01856ae

Please sign in to comment.