From a54553c858bdd210f1d1df17e227c8b849e452fe Mon Sep 17 00:00:00 2001 From: James Shubin Date: Mon, 15 Sep 2025 04:02:23 -0400 Subject: [PATCH] engine: resources: Print a warning if svc is slow The biggest horror is blocked execution somewhere, so if the svc start, stop or reload is being slow, then at least print a message to warn us. --- engine/resources/svc.go | 56 +++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/engine/resources/svc.go b/engine/resources/svc.go index 583d4a8f..245ec8a0 100644 --- a/engine/resources/svc.go +++ b/engine/resources/svc.go @@ -483,15 +483,27 @@ func (obj *SvcRes) CheckApply(ctx context.Context, apply bool) (bool, error) { } refresh = false // We did a start or stop, so a reload is not needed. - // TODO: Do we need a timeout here? - select { - case status, ok = <-result: - if !ok { - return false, fmt.Errorf("unexpected closed channel during start/stop") - } + // TODO: Should we permanenty error after a long timeout here? + for { + warn := true // warn once + select { + case status, ok = <-result: + if !ok { + return false, fmt.Errorf("unexpected closed channel during start/stop") + } + break - case <-ctx.Done(): - return false, ctx.Err() + case <-time.After(10 * time.Second): + if warn { + obj.init.Logf("service start/stop is slow...") + } + warn = false + continue + + case <-ctx.Done(): + return false, ctx.Err() + } + break // don't loop forever } switch status { @@ -537,15 +549,27 @@ func (obj *SvcRes) CheckApply(ctx context.Context, apply bool) (bool, error) { return false, errwrap.Wrapf(err, "failed to reload unit") } - // TODO: Do we need a timeout here? - select { - case status, ok = <-result: - if !ok { - return false, fmt.Errorf("unexpected closed channel during reload") - } + // TODO: Should we permanenty error after a long timeout here? + for { + warn := true // warn once + select { + case status, ok = <-result: + if !ok { + return false, fmt.Errorf("unexpected closed channel during reload") + } + break - case <-ctx.Done(): - return false, ctx.Err() + case <-time.After(10 * time.Second): + if warn { + obj.init.Logf("service start/stop is slow...") + } + warn = false + continue + + case <-ctx.Done(): + return false, ctx.Err() + } + break // don't loop forever } switch status {