Skip to content

Commit 4626db1

Browse files
committed
Use SIGKILL when SIGTERM doesn't work
Firecracker's master version cannot be killed by "runc kill" somehow. While it should be fixed by Firecracker, firecracker-containerd also should use SIGKILL when SIGTERM doesn't work. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent a81f236 commit 4626db1

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

runtime/jailer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type jailer interface {
5353
StubDrivesOptions() []FileOpt
5454

5555
// Stop the jailer as a way that is visible from the user-level process (e.g. SIGTERM).
56-
Stop() error
56+
Stop(force bool) error
5757

5858
// Close will do any necessary cleanup that the jailer has accrued.
5959
Close() error

runtime/noop_jailer.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,22 @@ func (j *noopJailer) StubDrivesOptions() []FileOpt {
101101
return []FileOpt{}
102102
}
103103

104-
func (j *noopJailer) Stop() error {
104+
func (j *noopJailer) Stop(force bool) error {
105105
if j.pid == 0 {
106106
return errors.New("the machine hasn't been started")
107107
}
108108

109-
j.logger.Debugf("sending SIGTERM to %d", j.pid)
109+
signal := syscall.SIGTERM
110+
if force {
111+
signal = syscall.SIGKILL
112+
}
113+
j.logger.Debugf("sending signal %d to %d", signal, j.pid)
110114
p, err := os.FindProcess(j.pid)
111115
if err != nil {
112116
return err
113117
}
114118

115-
err = p.Signal(syscall.SIGTERM)
119+
err = p.Signal(signal)
116120
if err == nil || err.Error() == "os: process already finished" {
117121
return nil
118122
}

runtime/runc_jailer.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,10 @@ func getNetNS(spec specs.Spec) string {
544544
return ""
545545
}
546546

547-
func (j runcJailer) Stop() error {
548-
return j.runcClient.Kill(j.ctx, j.vmID, int(syscall.SIGTERM), &runc.KillOpts{All: true})
547+
func (j runcJailer) Stop(force bool) error {
548+
signal := syscall.SIGTERM
549+
if force {
550+
signal = syscall.SIGKILL
551+
}
552+
return j.runcClient.Kill(j.ctx, j.vmID, int(signal), &runc.KillOpts{All: true})
549553
}

runtime/service.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,9 +1234,16 @@ func (s *service) shutdownLoop(
12341234
timeout: timeout,
12351235
},
12361236
{
1237-
name: "stop the jailer",
1237+
name: "stop the jailer by SIGTERM",
12381238
shutdown: func() error {
1239-
return s.jailer.Stop()
1239+
return s.jailer.Stop(false)
1240+
},
1241+
timeout: jailerStopTimeout,
1242+
},
1243+
{
1244+
name: "stop the jailer by SIGKILL",
1245+
shutdown: func() error {
1246+
return s.jailer.Stop(true)
12401247
},
12411248
timeout: jailerStopTimeout,
12421249
},

0 commit comments

Comments
 (0)