Skip to content

Commit

Permalink
Fix error when terminating the VM
Browse files Browse the repository at this point in the history
Error:

```
Cannot read properties of undefined (reading 'pid')
```
  • Loading branch information
jacob-carlborg committed Dec 15, 2023
1 parent d59f08d commit 9fee7b6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,5 +394,5 @@ jobs:
architecture: x86-64
version: '13.2'
hypervisor: qemu
shutdown_vm: false
shutdown_vm: true
run: test -f foo.txt
14 changes: 14 additions & 0 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.

28 changes: 25 additions & 3 deletions src/vm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs'
import * as path from 'path'
import {ChildProcess, spawn} from 'child_process'
import {spawn} from 'child_process'

import * as core from '@actions/core'
import * as exec from '@actions/exec'
Expand Down Expand Up @@ -34,16 +34,38 @@ export interface Configuration {
firmware?: fs.PathLike
}

interface Process {
readonly pid: number
readonly exitCode: number | null

unref(): void
}

class LiveProcess implements Process {
readonly exitCode: number | null = null
private _pid?: number

get pid(): number {
if (this._pid !== undefined) return this._pid

return (this._pid = +fs.readFileSync(Vm.pidfile, 'utf8'))
}

unref(): void {
// noop
}
}

export abstract class Vm {
ipAddress!: string

static readonly user = 'runner'
static readonly cpaHost = 'cross_platform_actions_host'
protected static readonly pidfile = '/tmp/cross-platform-actions.pid'
static readonly pidfile = '/tmp/cross-platform-actions.pid'
private static _isRunning?: boolean

readonly hypervisorPath: fs.PathLike
protected vmProcess!: ChildProcess
protected vmProcess: Process = new LiveProcess()
protected readonly architecture: architecture.Architecture
protected readonly configuration: vm.Configuration
protected readonly hypervisorDirectory: fs.PathLike
Expand Down

0 comments on commit 9fee7b6

Please sign in to comment.