Harden sidecar startup failure handling
This commit is contained in:
parent
6931d9d2b6
commit
5e2a49002e
3 changed files with 18 additions and 2 deletions
|
|
@ -1 +0,0 @@
|
|||
- @hardening pkg/display/sidecar.go:15 — `registerSidecarActions` ignores the error from `Start`, so a failed sidecar launch can still be treated as ready.
|
||||
|
|
@ -12,7 +12,12 @@ import (
|
|||
func (s *Service) registerSidecarActions() {
|
||||
if strings.TrimSpace(core.Env("CORE_DENO_ENABLE")) != "" && s.sidecar == nil {
|
||||
s.sidecar = s.ensureSidecar()
|
||||
_, _ = s.sidecar.Start(context.Background())
|
||||
if _, err := s.sidecar.Start(context.Background()); err != nil {
|
||||
if s != nil && s.ServiceRuntime != nil && s.Core() != nil {
|
||||
s.Core().LogError(err, "display.registerSidecarActions", "failed to start enabled sidecar")
|
||||
}
|
||||
s.sidecar = nil
|
||||
}
|
||||
}
|
||||
|
||||
s.Core().Action("display.sidecar.start", func(ctx context.Context, _ core.Options) core.Result {
|
||||
|
|
|
|||
|
|
@ -58,6 +58,18 @@ func TestSidecar_EnsureSidecar_Ugly(t *testing.T) {
|
|||
assert.Equal(t, "deno", manager.Status().Binary)
|
||||
}
|
||||
|
||||
func TestSidecar_RegisterActions_StartFailureClearsSidecar(t *testing.T) {
|
||||
t.Setenv("CORE_DENO_ENABLE", "1")
|
||||
t.Setenv("CORE_DENO_BINARY", "/definitely/not/a/real/deno")
|
||||
|
||||
c := core.New(core.WithServiceLock())
|
||||
svc := &Service{ServiceRuntime: core.NewServiceRuntime(c, Options{})}
|
||||
|
||||
svc.registerSidecarActions()
|
||||
|
||||
assert.Nil(t, svc.sidecar)
|
||||
}
|
||||
|
||||
func TestSidecar_StatusAction_Good(t *testing.T) {
|
||||
t.Setenv("CORE_DENO_BINARY", "/opt/core/deno")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue