Skip to content

Commit

Permalink
Fix windows installer stuck in pending state forever (#22592)
Browse files Browse the repository at this point in the history
  • Loading branch information
mna authored Oct 2, 2024
1 parent 8cfa35c commit 38fe6d9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions orbit/changes/22558-fix-stuck-windows-installers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Added a timeout to all script executions during software installs to prevent having install requests stuck in pending state forever.
14 changes: 11 additions & 3 deletions orbit/pkg/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pkg/scripts/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 38fe6d9

Please sign in to comment.