forked from containerd/go-runc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle runc command context manually
instead of defering to Go's stdlib to handle context, which only sends SIGKILL when the context timed out, handle the context timeout ourselves so we can inject a custom signal first ( default to SIGTERM, and send SIGKILL after 10 seconds) to stop container more gracefully. If no signal is specified, then fall back to sending SIGKILL just like stdlib. Fix containerd#21
- Loading branch information
Showing
5 changed files
with
115 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package runc | ||
|
||
import ( | ||
"context" | ||
"os/exec" | ||
"testing" | ||
"time" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func TestMonitorCustomSignal(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
defer cancel() | ||
cmd := exec.Command("sleep", "10") | ||
monitor := DefaultMonitor(unix.SIGTERM, time.Second) | ||
ec, err := monitor.Start(ctx, cmd) | ||
if err != nil { | ||
t.Errorf("Failed to start command: %v", err) | ||
} | ||
e := <-ec | ||
if e.Signal != unix.SIGTERM { | ||
t.Errorf("Got signal (%v), expected (%v)", e.Signal, unix.SIGTERM) | ||
} | ||
} | ||
|
||
func TestMonitorKill(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
defer cancel() | ||
cmd := exec.Command("sleep", "10") | ||
monitor := &defaultMonitor{} | ||
ec, err := monitor.Start(ctx, cmd) | ||
if err != nil { | ||
t.Errorf("Failed to start command: %v", err) | ||
} | ||
e := <-ec | ||
if e.Signal != unix.SIGKILL { | ||
t.Errorf("Got signal (%v), expected (%v)", e.Signal, unix.SIGTERM) | ||
} | ||
} |
Oops, something went wrong.