container/params: expose pipe deadline
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m21s
Test / Hakurei (push) Successful in 3m12s
Test / Sandbox (race detector) (push) Successful in 4m5s
Test / Hpkg (push) Successful in 4m8s
Test / Hakurei (race detector) (push) Successful in 4m54s
Test / Flake checks (push) Successful in 1m20s
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m21s
Test / Hakurei (push) Successful in 3m12s
Test / Sandbox (race detector) (push) Successful in 4m5s
Test / Hpkg (push) Successful in 4m8s
Test / Hakurei (race detector) (push) Successful in 4m54s
Test / Flake checks (push) Successful in 1m20s
This allows more graceful handling of unresponsive process. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
6a0ecced90
commit
8b9652fc72
@ -25,6 +25,9 @@ const (
|
|||||||
// CancelSignal is the signal expected by container init on context cancel.
|
// CancelSignal is the signal expected by container init on context cancel.
|
||||||
// A custom [Container.Cancel] function must eventually deliver this signal.
|
// A custom [Container.Cancel] function must eventually deliver this signal.
|
||||||
CancelSignal = SIGUSR2
|
CancelSignal = SIGUSR2
|
||||||
|
|
||||||
|
// Timeout from setup pipe creation to when initParams is fully written.
|
||||||
|
initSetupTimeout = 5 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -228,7 +231,7 @@ func (p *Container) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// place setup pipe before user supplied extra files, this is later restored by init
|
// place setup pipe before user supplied extra files, this is later restored by init
|
||||||
if fd, e, err := Setup(&p.cmd.ExtraFiles); err != nil {
|
if fd, e, err := Setup(time.Now().Add(initSetupTimeout), &p.cmd.ExtraFiles); err != nil {
|
||||||
return &StartError{true, "set up params stream", err, false, false}
|
return &StartError{true, "set up params stream", err, false, false}
|
||||||
} else {
|
} else {
|
||||||
p.setup = e
|
p.setup = e
|
||||||
@ -324,15 +327,13 @@ func (p *Container) Serve() error {
|
|||||||
p.SeccompRules = make([]seccomp.NativeRule, 0)
|
p.SeccompRules = make([]seccomp.NativeRule, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := setup.Encode(
|
err := setup.Encode(&initParams{
|
||||||
&initParams{
|
p.Params,
|
||||||
p.Params,
|
Getuid(),
|
||||||
Getuid(),
|
Getgid(),
|
||||||
Getgid(),
|
len(p.ExtraFiles),
|
||||||
len(p.ExtraFiles),
|
p.msg.IsVerbose(),
|
||||||
p.msg.IsVerbose(),
|
})
|
||||||
},
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.cancel()
|
p.cancel()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,13 +6,18 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Setup appends the read end of a pipe for setup params transmission and returns its fd.
|
// Setup appends the read end of a pipe for setup params transmission and returns its fd.
|
||||||
func Setup(extraFiles *[]*os.File) (int, *gob.Encoder, error) {
|
func Setup(deadline time.Time, extraFiles *[]*os.File) (int, *gob.Encoder, error) {
|
||||||
if r, w, err := os.Pipe(); err != nil {
|
if r, w, err := os.Pipe(); err != nil {
|
||||||
return -1, nil, err
|
return -1, nil, err
|
||||||
} else {
|
} else {
|
||||||
|
if err = w.SetDeadline(deadline); err != nil {
|
||||||
|
return -1, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
fd := 3 + len(*extraFiles)
|
fd := 3 + len(*extraFiles)
|
||||||
*extraFiles = append(*extraFiles, r)
|
*extraFiles = append(*extraFiles, r)
|
||||||
return fd, gob.NewEncoder(w), nil
|
return fd, gob.NewEncoder(w), nil
|
||||||
|
|||||||
@ -59,7 +59,8 @@ func TestSetupReceive(t *testing.T) {
|
|||||||
|
|
||||||
encoderDone := make(chan error, 1)
|
encoderDone := make(chan error, 1)
|
||||||
extraFiles := make([]*os.File, 0, 1)
|
extraFiles := make([]*os.File, 0, 1)
|
||||||
if fd, encoder, err := container.Setup(&extraFiles); err != nil {
|
deadline, _ := t.Deadline()
|
||||||
|
if fd, encoder, err := container.Setup(deadline, &extraFiles); err != nil {
|
||||||
t.Fatalf("Setup: error = %v", err)
|
t.Fatalf("Setup: error = %v", err)
|
||||||
} else if fd != 3 {
|
} else if fd != 3 {
|
||||||
t.Fatalf("Setup: fd = %d, want 3", fd)
|
t.Fatalf("Setup: fd = %d, want 3", fd)
|
||||||
|
|||||||
@ -20,8 +20,12 @@ import (
|
|||||||
"hakurei.app/system"
|
"hakurei.app/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Duration to wait for shim to exit on top of container WaitDelay.
|
const (
|
||||||
const shimWaitTimeout = 5 * time.Second
|
// Duration to wait for shim to exit on top of container WaitDelay.
|
||||||
|
shimWaitTimeout = 5 * time.Second
|
||||||
|
// Timeout from setup pipe creation to when outcomeState is fully written.
|
||||||
|
shimSetupTimeout = 5 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
// mainState holds persistent state bound to outcome.main.
|
// mainState holds persistent state bound to outcome.main.
|
||||||
type mainState struct {
|
type mainState struct {
|
||||||
@ -214,7 +218,7 @@ func (k *outcome) main(msg message.Msg) {
|
|||||||
hsuPath := internal.MustHsuPath()
|
hsuPath := internal.MustHsuPath()
|
||||||
|
|
||||||
// ms.beforeExit required beyond this point
|
// ms.beforeExit required beyond this point
|
||||||
ms := &mainState{Msg: msg, k: k}
|
ms := mainState{Msg: msg, k: k}
|
||||||
|
|
||||||
if err := k.sys.Commit(); err != nil {
|
if err := k.sys.Commit(); err != nil {
|
||||||
ms.fatal("cannot commit system setup:", err)
|
ms.fatal("cannot commit system setup:", err)
|
||||||
@ -232,11 +236,12 @@ func (k *outcome) main(msg message.Msg) {
|
|||||||
// shim runs in the same session as monitor; see shim.go for behaviour
|
// shim runs in the same session as monitor; see shim.go for behaviour
|
||||||
ms.cmd.Cancel = func() error { return ms.cmd.Process.Signal(syscall.SIGCONT) }
|
ms.cmd.Cancel = func() error { return ms.cmd.Process.Signal(syscall.SIGCONT) }
|
||||||
|
|
||||||
var e *gob.Encoder
|
var outcomeStateEncoder *gob.Encoder
|
||||||
if fd, encoder, err := container.Setup(&ms.cmd.ExtraFiles); err != nil {
|
if fd, encoder, err := container.Setup(time.Now().Add(shimSetupTimeout), &ms.cmd.ExtraFiles); err != nil {
|
||||||
ms.fatal("cannot create shim setup pipe:", err)
|
ms.fatal("cannot create shim setup pipe:", err)
|
||||||
|
panic("unreachable")
|
||||||
} else {
|
} else {
|
||||||
e = encoder
|
outcomeStateEncoder = encoder
|
||||||
ms.cmd.Env = []string{
|
ms.cmd.Env = []string{
|
||||||
// passed through to shim by hsu
|
// passed through to shim by hsu
|
||||||
shimEnv + "=" + strconv.Itoa(fd),
|
shimEnv + "=" + strconv.Itoa(fd),
|
||||||
@ -262,22 +267,9 @@ func (k *outcome) main(msg message.Msg) {
|
|||||||
go func() { ms.cmdWait <- ms.cmd.Wait(); cancel() }()
|
go func() { ms.cmdWait <- ms.cmd.Wait(); cancel() }()
|
||||||
ms.Time = &startTime
|
ms.Time = &startTime
|
||||||
|
|
||||||
// unfortunately the I/O here cannot be directly canceled;
|
if err := outcomeStateEncoder.Encode(k.state); err != nil {
|
||||||
// the cancellation path leads to fatal in this case so that is fine
|
|
||||||
select {
|
|
||||||
case err := <-func() (setupErr chan error) {
|
|
||||||
setupErr = make(chan error, 1)
|
|
||||||
go func() { setupErr <- e.Encode(k.state) }()
|
|
||||||
return
|
|
||||||
}():
|
|
||||||
if err != nil {
|
|
||||||
msg.Resume()
|
|
||||||
ms.fatal("cannot transmit shim config:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
case <-ctx.Done():
|
|
||||||
msg.Resume()
|
msg.Resume()
|
||||||
ms.fatal("shim context canceled:", newWithMessageError("shim setup canceled", ctx.Err()))
|
ms.fatal("cannot transmit shim config:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// shim accepted setup payload, create process state
|
// shim accepted setup payload, create process state
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user