{"record":{"id":"832565993c4bb723","repo":"juicedata/juicefs","slug":"failed-to-execute-command-s-v","errorCode":null,"errorMessage":"failed to execute command `%s`: %v","messagePattern":"failed to execute command `(.+?)`: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/debug.go","lineNumber":179,"sourceCode":"\n\tif cfg.Port != nil {\n\t\tif len(strings.Split(cfg.Port.DebugAgent, \":\")) >= 2 {\n\t\t\tif port, err := strconv.Atoi(strings.Split(cfg.Port.DebugAgent, \":\")[1]); err != nil {\n\t\t\t\tlogger.Warnf(\"failed to parse debug agent port: %v\", err)\n\t\t\t} else {\n\t\t\t\treturn port, nil\n\t\t\t}\n\t\t}\n\t}\n\n\tvar lsofArgs []string\n\tif requireRootPrivileges {\n\t\tlsofArgs = append(lsofArgs, \"sudo\")\n\t}\n\tlsofArgs = append(lsofArgs, \"/bin/sh\", \"-c\", \"lsof -i -nP | grep -v grep | grep LISTEN | grep \"+pid)\n\tret, err := exec.Command(lsofArgs[0], lsofArgs[1:]...).CombinedOutput()\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to execute command `%s`: %v\", strings.Join(lsofArgs, \" \"), err)\n\t}\n\tlogger.Debugf(\"lsof output: \\n%s\", string(ret))\n\tlines := strings.Split(string(ret), \"\\n\")\n\tif len(lines) == 0 {\n\t\treturn 0, fmt.Errorf(\"pprof will be collected, but no listen port\")\n\t}\n\n\tvar listenPort = -1\n\tfor _, line := range lines {\n\t\tfields := strings.Fields(line)\n\t\tif len(fields) != 0 {\n\t\t\tport, err := func() (port int, err error) {\n\t\t\t\tdefer func() {\n\t\t\t\t\te := recover()\n\t\t\t\t\tif e != nil {\n\t\t\t\t\t\terr = fmt.Errorf(\"failed to parse listen port: %v\", e)\n\t\t\t\t\t}\n\t\t\t\t}()","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/cmd/debug.go#L161-L197","documentation":"`juicefs debug`'s `getPprofPort` shells out to `lsof -i -nP | grep LISTEN | grep <pid>` to discover the JuiceFS process's pprof port. When that shell pipeline fails to execute or exits non-zero, the command wraps the failure in this error. Note lsof exits non-zero when it finds nothing, so a process with no listening sockets also produces this error.","triggerScenarios":"Running `juicefs debug <mnt>` where lsof is not installed (exec fails with 'executable file not found'), the user lacks permission to inspect the target process's sockets, or the target PID has no listening sockets so lsof returns exit code 1.","commonSituations":"Minimal containers/images without the `lsof` package; running `juicefs debug` as non-root against a root-owned mount process without sudo; the process crashed or never opened its debug agent port 6060-6099.","solutions":["Install lsof (`apt-get install lsof` / `yum install lsof`) in the environment where debug runs.","Run the debug command with sufficient privileges (root, or allow the sudo path) so lsof can inspect the target process.","Verify manually with `lsof -i -nP | grep LISTEN | grep <pid>`; ensure the debug agent is enabled and the process is alive.","If the process genuinely has no listening port, collect profiles via an explicitly configured debug-agent address instead."],"exampleFix":"// before (inside container)\njuicefs debug /mnt/jfs\n// failed to execute command `/bin/sh -c lsof -i -nP | ...`: exec: \"lsof\": executable file not found\n// after\napt-get install -y lsof && juicefs debug /mnt/jfs","handlingStrategy":"fallback","validationCode":"command -v lsof >/dev/null 2>&1 || { echo \"lsof required for juicefs debug\"; exit 1; }\nlsof -i -nP | grep LISTEN | grep $PID || echo \"no listening sockets for $PID\"","typeGuard":null,"tryCatchPattern":"if out, err := debugCmd.CombinedOutput(); err != nil {\n    if strings.Contains(string(out), \"failed to execute command\") {\n        log.Printf(\"debug unavailable (missing lsof or no permission): %v\", err)\n        return\n    }\n}","preventionTips":["Ensure lsof is installed in every environment where juicefs debug runs.","Run debug with root privileges or configure sudo for the target user.","Confirm the target PID is alive and has listening sockets before debugging."],"tags":["cli","debug","lsof","process"],"backgroundTag":"command-not-found","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}