@@ -190,8 +190,7 @@ func (m *manager) shutdownHypervisor(ctx context.Context, inst *Instance) error
190190
191191 // Wait for process to exit
192192 if inst .HypervisorPID != nil {
193- if ! WaitForProcessExit (* inst .HypervisorPID , 2 * time .Second ) {
194- log .WarnContext (ctx , "hypervisor did not exit gracefully in time, force killing process" , "instance_id" , inst .Id , "pid" , * inst .HypervisorPID )
193+ forceKill := func () error {
195194 if err := syscall .Kill (* inst .HypervisorPID , syscall .SIGKILL ); err != nil && err != syscall .ESRCH {
196195 return fmt .Errorf ("force kill hypervisor pid %d: %w" , * inst .HypervisorPID , err )
197196 }
@@ -202,6 +201,19 @@ func (m *manager) shutdownHypervisor(ctx context.Context, inst *Instance) error
202201 return fmt .Errorf ("hypervisor pid %d did not exit after SIGKILL" , * inst .HypervisorPID )
203202 }
204203 }
204+ return nil
205+ }
206+
207+ if shutdownErr == hypervisor .ErrNotSupported {
208+ log .DebugContext (ctx , "hypervisor does not support graceful shutdown, force killing process" , "instance_id" , inst .Id , "pid" , * inst .HypervisorPID )
209+ if err := forceKill (); err != nil {
210+ return err
211+ }
212+ } else if ! WaitForProcessExit (* inst .HypervisorPID , 2 * time .Second ) {
213+ log .WarnContext (ctx , "hypervisor did not exit gracefully in time, force killing process" , "instance_id" , inst .Id , "pid" , * inst .HypervisorPID )
214+ if err := forceKill (); err != nil {
215+ return err
216+ }
205217 } else {
206218 log .DebugContext (ctx , "hypervisor shutdown gracefully" , "instance_id" , inst .Id , "pid" , * inst .HypervisorPID )
207219 }
0 commit comments