Skip to content

Commit

Permalink
Merge pull request #524 from jakob-tsd/losetup_retry
Browse files Browse the repository at this point in the history
ImagePartitionAction: retry losetup.Attach()
  • Loading branch information
obbardc authored Dec 17, 2024
2 parents 78aad24 + db6b23c commit f219e0a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions actions/image_partition_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,19 @@ func (i *ImagePartitionAction) PreNoMachine(context *debos.DebosContext) error {

img.Close()

i.loopDev, err = losetup.Attach(imagePath, 0, false)
// losetup.Attach() can fail due to concurrent attaches in other processes
retries := 60
for t := 1; t <= retries; t++ {
i.loopDev, err = losetup.Attach(imagePath, 0, false)
if err == nil {
break
}
log.Printf("Setup loop device: try %d/%d failed: %v", t, retries, err)
time.Sleep(200 * time.Millisecond)
}

if err != nil {
return fmt.Errorf("Failed to setup loop device")
return fmt.Errorf("Failed to setup loop device: %v", err)
}
context.Image = i.loopDev.Path()
i.usingLoop = true
Expand Down

0 comments on commit f219e0a

Please sign in to comment.