diff --git a/pkg/mount/mount.go b/pkg/mount/mount.go index 5f601e6..1ded830 100644 --- a/pkg/mount/mount.go +++ b/pkg/mount/mount.go @@ -92,6 +92,7 @@ func (s *State) RunStageOp(stage string) func(context.Context) error { func (s *State) MountOP(what, where, t string, options []string, timeout time.Duration) func(context.Context) error { s.Logger.Debug().Str("what", what).Str("where", where).Str("type", t) return func(c context.Context) error { + cc := time.After(timeout) for { select { default: @@ -119,7 +120,7 @@ func (s *State) MountOP(what, where, t string, options []string, timeout time.Du return nil case <-c.Done(): return fmt.Errorf("context canceled") - case <-time.After(timeout): + case <-cc: return fmt.Errorf("timeout exhausted") } } diff --git a/pkg/mount/mount_test.go b/pkg/mount/mount_test.go index 875e609..3993592 100644 --- a/pkg/mount/mount_test.go +++ b/pkg/mount/mount_test.go @@ -1,6 +1,9 @@ package mount_test import ( + "context" + "time" + "github.com/kairos-io/immucore/pkg/mount" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -97,5 +100,13 @@ var _ = Describe("mounting immutable setup", func() { Expect(dag[7][0].Name).To(Equal("mount-bind")) Expect(dag[8][0].Name).To(Equal("write-fstab")) }) + + It("Mountop timeouts", func() { + s := &mount.State{} + f := s.MountOP("", "", "", []string{}, 1*time.Second) + err := f(context.Background()) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring("exhausted")) + }) }) })