Skip to content

Commit

Permalink
Test with stat that doesn't hang.
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Hallgren <thomas@datawire.io>
  • Loading branch information
thallgren committed Feb 3, 2024
1 parent d53a256 commit 5b8d2ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
9 changes: 4 additions & 5 deletions pkg/fs/fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ func NewHost(fsh fuse.FileSystemInterface, mountPoint string) *FuseHost {

// Start will mount the filesystem on the mountPoint passed to NewHost.
func (fh *FuseHost) Start(ctx context.Context, startTimeout time.Duration) error {
ctx, cancel := context.WithCancel(ctx)
fh.cancel = cancel
ctx, fh.cancel = context.WithCancel(ctx)

opts := []string{
"-o", "default_permissions",
"-o", "auto_cache",
"-o", "sync_read",
"-o", "allow_root",
}
if logrus.GetLevel() >= logrus.DebugLevel {
opts = append(opts, "-o", "debug")
}
if runtime.GOOS == "windows" {
// WinFsp requires this to create files with the same
// user as the one that starts the FUSE mount
Expand All @@ -47,9 +49,6 @@ func (fh *FuseHost) Start(ctx context.Context, startTimeout time.Duration) error
startCtx, startCancel := context.WithTimeout(ctx, startTimeout)
defer startCancel()
go fh.detectFuseStarted(startCtx, started)
if logrus.GetLevel() >= logrus.DebugLevel {
opts = append(opts, "-o", "debug")
}

mCh := make(chan bool, 1)
fh.wg.Add(1)
Expand Down
29 changes: 24 additions & 5 deletions pkg/fs/fuse_started_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import (
)

func (fh *FuseHost) detectFuseStarted(ctx context.Context, started chan error) {
time.Sleep(100 * time.Millisecond)
var st unix.Stat_t
if err := unix.Stat(fh.mountPoint, &st); err != nil {
st, err := statWithTimeout(ctx, fh.mountPoint, 10*time.Millisecond)
if err != nil {
select {
case started <- fmt.Errorf("unable to stat mount point %q: %v", fh.mountPoint, err):
default:
Expand All @@ -39,8 +38,7 @@ func (fh *FuseHost) detectFuseStarted(ctx context.Context, started chan error) {
}
return
case <-ticker.C:
var mountSt unix.Stat_t
if err := unix.Stat(fh.mountPoint, &mountSt); err != nil {
if mountSt, err := statWithTimeout(ctx, fh.mountPoint, 20*time.Millisecond); err != nil {
// we don't consider a failure to stat an error here, just a cause for a retry.
logrus.Debugf("unable to stat mount point %q: %v", fh.mountPoint, err)
} else {
Expand All @@ -51,3 +49,24 @@ func (fh *FuseHost) detectFuseStarted(ctx context.Context, started chan error) {
}
}
}

// statWithTimeout performs a normal unix.Stat but will not allow that it hangs for
// more than the given timeout.
func statWithTimeout(ctx context.Context, path string, timeout time.Duration) (*unix.Stat_t, error) {
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
errCh := make(chan error, 1)
mountSt := new(unix.Stat_t)
go func() {
errCh <- unix.Stat(path, mountSt)
}()
select {
case <-ctx.Done():
return nil, ctx.Err()
case err := <-errCh:
if err != nil {
return nil, err
}
return mountSt, nil
}
}

0 comments on commit 5b8d2ac

Please sign in to comment.