Skip to content

Commit

Permalink
Kill mount process and dump its stack when mount point is not ready i…
Browse files Browse the repository at this point in the history
…n time (#5171)

Signed-off-by: Changxin Miao <[email protected]>
  • Loading branch information
polyrabbit authored Sep 18, 2024
1 parent 7ac8f01 commit 84c3e43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions cmd/mount_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import (
"github.com/juicedata/juicefs/pkg/vfs"
)

var mountPid int

func showThreadStack(agentAddr string) {
if agentAddr == "" {
return
Expand Down Expand Up @@ -224,10 +226,15 @@ func checkMountpoint(name, mp, logPath string, background bool) {
_ = os.Stdout.Sync()
}
_, _ = os.Stdout.WriteString("\n")
mountDesc := "mount process is not started yet"
if mountPid != 0 {
mountDesc = fmt.Sprintf("tried to kill mount process %d", mountPid)
_ = syscall.Kill(mountPid, syscall.SIGABRT) // Kill and show stack trace
}
if background {
logger.Fatalf("The mount point is not ready in %d seconds, please check the log (%s) or re-mount in foreground", mountTimeOut, logPath)
logger.Fatalf("The mount point is not ready in %d seconds (%s), please check the log (%s) or re-mount in foreground", mountTimeOut, mountDesc, logPath)
} else {
logger.Fatalf("The mount point is not ready in %d seconds, exit it", mountTimeOut)
logger.Fatalf("The mount point is not ready in %d seconds (%s), exit it", mountTimeOut, mountDesc)
}
}

Expand Down Expand Up @@ -759,6 +766,7 @@ func launchMount(mp string, conf *vfs.Config) error {
}
}

mountPid = 0
cmd := exec.Command(path, os.Args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
Expand All @@ -770,6 +778,7 @@ func launchMount(mp string, conf *vfs.Config) error {
continue
}
os.Unsetenv("_FUSE_STATE_PATH")
mountPid = cmd.Process.Pid

ctx, cancel := context.WithCancel(context.TODO())
go watchdog(ctx, mp)
Expand All @@ -790,6 +799,7 @@ func launchMount(mp string, conf *vfs.Config) error {
logger.Info("transfer FUSE session to others")
return nil
}
logger.Errorf("mount process %d: %s, will restart in 1 second", mountPid, err)
time.Sleep(time.Second)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/chunk/disk_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func (cache *cacheStore) createDir(dir string) {
cache.createDir(filepath.Dir(dir))
}
_ = os.Mkdir(dir, mode)
// umask may remove some permisssions
// umask may remove some permissions
return os.Chmod(dir, mode)
} else if strings.HasPrefix(dir, cache.dir) && err == nil && st.Mode() != mode {
changeMode(dir, st, mode)
Expand Down

0 comments on commit 84c3e43

Please sign in to comment.