Skip to content

Commit

Permalink
fix hang on start
Browse files Browse the repository at this point in the history
  • Loading branch information
sclevine committed Feb 28, 2025
1 parent ff81306 commit e0ff6a0
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tool/teleport-update/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os"
"os/signal"
"syscall"
"time"

"github.com/gravitational/trace"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -53,6 +54,8 @@ const (
updateGroupEnvVar = "TELEPORT_UPDATE_GROUP"
// updateVersionEnvVar forces the version to specified value.
updateVersionEnvVar = "TELEPORT_UPDATE_VERSION"
// updateLockTimeout is the duration commands will wait for update to complete before failing.
updateLockTimeout = 10 * time.Minute
)

var plog = logutils.NewPackageLogger(teleport.ComponentKey, teleport.ComponentUpdater)
Expand Down Expand Up @@ -274,7 +277,7 @@ func cmdDisable(ctx context.Context, ccfg *cliConfig) error {
if err != nil {
return trace.Wrap(err, "failed to initialize updater")
}
unlock, err := libutils.FSWriteLock(lockFile)
unlock, err := libutils.FSTryWriteLockTimeout(ctx, lockFile, updateLockTimeout)
if err != nil {
return trace.Wrap(err, "failed to grab concurrent execution lock %s", lockFile)
}
Expand All @@ -295,7 +298,7 @@ func cmdUnpin(ctx context.Context, ccfg *cliConfig) error {
if err != nil {
return trace.Wrap(err, "failed to setup updater")
}
unlock, err := libutils.FSWriteLock(lockFile)
unlock, err := libutils.FSTryWriteLockTimeout(ctx, lockFile, updateLockTimeout)
if err != nil {
return trace.Wrap(err, "failed to grab concurrent execution lock %n", lockFile)
}
Expand All @@ -318,7 +321,7 @@ func cmdInstall(ctx context.Context, ccfg *cliConfig) error {
}

// Ensure enable can't run concurrently.
unlock, err := libutils.FSWriteLock(lockFile)
unlock, err := libutils.FSTryWriteLockTimeout(ctx, lockFile, updateLockTimeout)
if err != nil {
return trace.Wrap(err, "failed to grab concurrent execution lock %s", lockFile)
}
Expand All @@ -340,7 +343,12 @@ func cmdUpdate(ctx context.Context, ccfg *cliConfig) error {
return trace.Wrap(err, "failed to initialize updater")
}
// Ensure update can't run concurrently.
unlock, err := libutils.FSWriteLock(lockFile)
var unlock func() error
if ccfg.UpdateNow {
unlock, err = libutils.FSTryWriteLockTimeout(ctx, lockFile, updateLockTimeout)
} else {
unlock, err = libutils.FSWriteLock(lockFile)
}
if err != nil {
return trace.Wrap(err, "failed to grab concurrent execution lock %s", lockFile)
}
Expand Down Expand Up @@ -456,7 +464,7 @@ func cmdUninstall(ctx context.Context, ccfg *cliConfig) error {
return trace.Wrap(err, "failed to initialize updater")
}
// Ensure update can't run concurrently.
unlock, err := libutils.FSWriteLock(lockFile)
unlock, err := libutils.FSTryWriteLockTimeout(ctx, lockFile, updateLockTimeout)
if err != nil {
return trace.Wrap(err, "failed to grab concurrent execution lock %s", lockFile)
}
Expand Down

0 comments on commit e0ff6a0

Please sign in to comment.