Skip to content

Commit

Permalink
fix: retry blockdevice open in the installer
Browse files Browse the repository at this point in the history
We had these retries in other places, but not here.

This seems to happen more frequently with Linux 6.6 update, the tl;dr is
same: `udevd` tries to rescan the partition table at the wrong moment,
preventing Talos installer to open the partition which was just created.

It's a race, so workaround it by retrying the call.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Jan 31, 2024
1 parent 593afee commit a5e13c6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cmd/installer/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
"fmt"
"log"
"os"
"time"

"github.com/siderolabs/go-blockdevice/blockdevice"
"github.com/siderolabs/go-procfs/procfs"
"github.com/siderolabs/go-retry/retry"

"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/board"
Expand Down Expand Up @@ -229,7 +231,7 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {

var bd *blockdevice.BlockDevice

bd, err = blockdevice.Open(device)
bd, err = retryBlockdeviceOpen(device)
if err != nil {
return err
}
Expand Down Expand Up @@ -368,3 +370,20 @@ func (i *Installer) runPreflightChecks(mode Mode) error {

return checks.Run(ctx)
}

func retryBlockdeviceOpen(device string) (*blockdevice.BlockDevice, error) {
var bd *blockdevice.BlockDevice

err := retry.Constant(10*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(func() error {
var openErr error

bd, openErr = blockdevice.Open(device)
if openErr != nil && os.IsNotExist(openErr) {
return retry.ExpectedError(openErr)
}

return openErr
})

return bd, err
}

0 comments on commit a5e13c6

Please sign in to comment.