Skip to content

Commit 844cded

Browse files
committed
qemu: fixes graceful_shutdown to wait kill_timeout before signalling process
1 parent 52629ac commit 844cded

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

.changelog/27316.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
qemu: fixes graceful_shutdown to wait kill_timeout before signalling process
3+
```

drivers/qemu/driver.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,26 @@ func (d *Driver) StopTask(taskID string, timeout time.Duration, signal string) e
722722

723723
// Attempt a graceful shutdown only if it was configured in the job
724724
if handle.monitorPath != "" {
725-
if err := sendQemuShutdown(d.logger, handle.monitorPath, handle.pid); err != nil {
726-
d.logger.Debug("error sending graceful shutdown ", "pid", handle.pid, "error", err)
725+
err := sendQemuShutdown(d.logger, handle.monitorPath, handle.pid)
726+
if err == nil {
727+
ctx, cancel := context.WithTimeout(context.Background(), timeout)
728+
defer cancel()
729+
ticker := time.NewTicker(1 * time.Second)
730+
defer ticker.Stop()
731+
out:
732+
for {
733+
select {
734+
case <-ctx.Done():
735+
d.logger.Error("graceful shutdown", "pid", handle.pid, "timeout after", timeout)
736+
break out
737+
case <-ticker.C:
738+
if handle.procState != drivers.TaskStateRunning {
739+
break out
740+
}
741+
}
742+
}
743+
} else {
744+
d.logger.Debug("error sending graceful shutdown", "pid", handle.pid, "error", err)
727745
}
728746
} else {
729747
d.logger.Debug("monitor socket is empty, forcing shutdown")

0 commit comments

Comments
 (0)