Skip to content

Commit

Permalink
refactor passing around new host uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
rosstimothy committed Oct 31, 2024
1 parent 600f581 commit 9ddb836
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/utils/hostid/hostid.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ func ReadOrCreateFile(dataDir string) (string, error) {
iterationLimit := 3

for i := 0; i < iterationLimit; i++ {
id, err := ReadFile(dataDir)
if err == nil {
return id, nil
}
if !trace.IsNotFound(err) {
if read, err := ReadFile(dataDir); err == nil {
return read, nil
} else if !trace.IsNotFound(err) {
return "", trace.Wrap(err)
}

Expand All @@ -103,9 +101,7 @@ func ReadOrCreateFile(dataDir string) (string, error) {
"Please try restarting Teleport again.")
}

id = rawID.String()

writeFile := func() (string, error) {
writeFile := func(potentialID string) (string, error) {
unlock, err := utils.FSTryWriteLock(hostUUIDFileLock)
if err != nil {
return "", trace.Wrap(err)
Expand All @@ -118,14 +114,14 @@ func ReadOrCreateFile(dataDir string) (string, error) {
return "", trace.Wrap(err)
}

if err := WriteFile(dataDir, id); err != nil {
if err := WriteFile(dataDir, potentialID); err != nil {
return "", trace.Wrap(err)
}

return id, nil
return potentialID, nil
}

id, err = writeFile()
id, err := writeFile(rawID.String())
if err != nil {
if errors.Is(err, utils.ErrUnsuccessfulLockTry) {
time.Sleep(10 * time.Millisecond)
Expand Down

0 comments on commit 9ddb836

Please sign in to comment.