Fix windows installer stuck in pending state forever (#22592)

This commit is contained in:
Martin Angers 2024-10-02 16:18:37 -04:00 committed by GitHub
parent 8cfa35c1c5
commit 38fe6d9a43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 3 deletions

View file

@ -0,0 +1 @@
* Added a timeout to all script executions during software installs to prevent having install requests stuck in pending state forever.

View file

@ -15,6 +15,7 @@ import (
"github.com/fleetdm/fleet/v4/orbit/pkg/constant"
"github.com/fleetdm/fleet/v4/orbit/pkg/scripts"
"github.com/fleetdm/fleet/v4/pkg/file"
pkgscripts "github.com/fleetdm/fleet/v4/pkg/scripts"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/fleetdm/fleet/v4/server/ptr"
"github.com/osquery/osquery-go"
@ -43,6 +44,9 @@ type Runner struct {
OsqueryClient QueryClient
OrbitClient Client
// limit execution time of the various scripts run during software installation
installerExecutionTimeout time.Duration
// osquerySocketPath is used to establish the osquery connection
// if it's ever lost or disconnected
osquerySocketPath string
@ -70,9 +74,10 @@ type Runner struct {
func NewRunner(client Client, socketPath string, scriptsEnabled func() bool) *Runner {
r := &Runner{
OrbitClient: client,
osquerySocketPath: socketPath,
scriptsEnabled: scriptsEnabled,
OrbitClient: client,
osquerySocketPath: socketPath,
scriptsEnabled: scriptsEnabled,
installerExecutionTimeout: pkgscripts.MaxHostSoftwareInstallExecutionTime,
}
return r
@ -277,6 +282,9 @@ func (r *Runner) runInstallerScript(ctx context.Context, scriptContents string,
return "", -1, fmt.Errorf("writing script: %w", err)
}
ctx, cancel := context.WithTimeout(context.Background(), r.installerExecutionTimeout)
defer cancel()
execFn := r.execCmdFn
if execFn == nil {
execFn = scripts.ExecCmd

View file

@ -13,4 +13,12 @@ const (
// to account for the notification system used to deliver scripts to the
// host.
MaxServerWaitTime = MaxHostExecutionTime + 1*time.Minute
// MaxHostSoftwareInstallExecutionTime is the maximum time allowed for a
// software installer script to run on a host before is terminated. That same
// timeout is used for all steps of the install process - install,
// post-install, "implicit" uninstall after a failure of the post-install
// script, and "explicit" uninstall request. This does NOT include the
// download time.
MaxHostSoftwareInstallExecutionTime = 1 * time.Hour
)