Skip to content

Commit 6734719

Browse files
committed
machine: StopVMM should not panic on nil Process
Fixes #37 Signed-off-by: Samuel Karp <[email protected]>
1 parent 4d64bf8 commit 6734719

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

machine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ func (m *Machine) StopVMM() error {
378378
}
379379

380380
func (m *Machine) stopVMM() error {
381-
if m.cmd != nil {
381+
if m.cmd != nil && m.cmd.Process != nil {
382382
log.Debug("stopVMM(): sending sigterm to firecracker")
383383
return m.cmd.Process.Signal(syscall.SIGTERM)
384384
}

machine_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ func TestMicroVMExecution(t *testing.T) {
118118

119119
vmmCtx, vmmCancel := context.WithTimeout(ctx, 30*time.Second)
120120
defer vmmCancel()
121-
var exitchannel <-chan error
121+
exitchannel := make(chan error)
122122
go func() {
123-
var err error
124-
exitchannel, err = m.startVMM(vmmCtx)
123+
exitCh, err := m.startVMM(vmmCtx)
125124
if err != nil {
125+
close(exitchannel)
126126
t.Fatalf("Failed to start VMM: %v", err)
127127
}
128+
exitchannel <- <-exitCh
129+
close(exitchannel)
128130
}()
129131
time.Sleep(2 * time.Second)
130132

@@ -139,7 +141,12 @@ func TestMicroVMExecution(t *testing.T) {
139141
t.Run("TestStartInstance", func(t *testing.T) { testStartInstance(vmmCtx, t, m) })
140142

141143
// Let the VMM start and stabilize...
142-
time.Sleep(5 * time.Second)
144+
timer := time.NewTimer(5 * time.Second)
145+
select {
146+
case <-timer.C:
147+
case <-exitchannel:
148+
// if we've already exited, there's no use waiting for the timer
149+
}
143150
t.Run("TestStopVMM", func(t *testing.T) { testStopVMM(ctx, t, m) })
144151
<-exitchannel
145152
}

0 commit comments

Comments
 (0)