From 1711b4abe046ada24d78abba50b7b015d3474da3 Mon Sep 17 00:00:00 2001 From: zackattack01 Date: Fri, 26 Jul 2024 16:07:56 -0400 Subject: [PATCH] push service configuration operations later in start routine --- cmd/launcher/svc_windows.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/launcher/svc_windows.go b/cmd/launcher/svc_windows.go index 6b84dc2f2..5e9f5be11 100644 --- a/cmd/launcher/svc_windows.go +++ b/cmd/launcher/svc_windows.go @@ -31,6 +31,14 @@ const serviceName = "launcher" // runWindowsSvc starts launcher as a windows service. This will // probably not behave correctly if you start it from the command line. +// This method is responsible for calling svc.Run, which eventually translates into the +// Execute function below. Each device has a global ServicesPipeTimeout value (typically at +// 30-45 seconds but depends on the configuration of the device). We have that many seconds +// to get from here to the point in Execute where we return a service status of Running before +// service control manager will consider the start attempt to have timed out, cancel it, +// and proceed without attempting restart. +// Wherever possible, we should keep any connections or timely operations out of this method, +// and ensure they are added late enough in Execute to avoid hitting this timeout. func runWindowsSvc(systemSlogger *multislogger.MultiSlogger, args []string) error { systemSlogger.Log(context.TODO(), slog.LevelInfo, "service start requested", @@ -65,9 +73,6 @@ func runWindowsSvc(systemSlogger *multislogger.MultiSlogger, args []string) erro systemSlogger.AddHandler(localSloggerHandler) } - // Confirm that service configuration is up-to-date - checkServiceConfiguration(localSlogger.Logger, opts) - systemSlogger.Log(context.TODO(), slog.LevelInfo, "launching service", "version", version.Version().Version, @@ -162,11 +167,17 @@ func (w *winSvc) Execute(args []string, r <-chan svc.ChangeRequest, changes chan const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown changes <- svc.Status{State: svc.StartPending} + w.systemSlogger.Log(ctx, slog.LevelInfo, "windows service starting", ) + // after this point windows service control manager will know that we've' successfully started, + // it is safe to begin longer running operations changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted} + // Confirm that service configuration is up-to-date + go checkServiceConfiguration(w.slogger.Logger, w.opts) + ctx = ctxlog.NewContext(ctx, w.logger) runLauncherResults := make(chan struct{})