{"record":{"id":"9cda183e6fd784ba","repo":"ipfs/kubo","slug":"finding-binary-path-w","errorCode":null,"errorMessage":"finding binary path: %w","messagePattern":"finding binary path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"profile/profile.go","lineNumber":232,"sourceCode":"\treturn pprof.Lookup(\"allocs\").WriteTo(w, 0)\n}\n\nfunc versionInfo(ctx context.Context, _ Options, w io.Writer) error {\n\treturn json.NewEncoder(w).Encode(version.GetVersionInfo())\n}\n\nfunc binary(ctx context.Context, _ Options, w io.Writer) error {\n\tvar (\n\t\tpath string\n\t\terr  error\n\t)\n\tif goos == \"linux\" {\n\t\tpid := os.Getpid()\n\t\tpath = fmt.Sprintf(\"/proc/%d/exe\", pid)\n\t} else {\n\t\tpath, err = os.Executable()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"finding binary path: %w\", err)\n\t\t}\n\t}\n\tfi, err := os.Open(path)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"opening binary %q: %w\", path, err)\n\t}\n\t_, err = io.Copy(w, fi)\n\t_ = fi.Close()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"copying binary %q: %w\", path, err)\n\t}\n\treturn nil\n}\n\nfunc mutexProfile(ctx context.Context, opts Options, w io.Writer) error {\n\tprev := runtime.SetMutexProfileFraction(opts.MutexProfileFraction)\n\tdefer runtime.SetMutexProfileFraction(prev)\n\terr := waitOrCancel(ctx, opts.ProfileDuration)","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/profile/profile.go#L214-L250","documentation":"The binary() collector embeds the running executable itself into the profile archive so dumps are debuggable later. On Linux it resolves /proc/<pid>/exe; on all other GOOS it calls os.Executable(). If os.Executable() fails, the error is wrapped as \"finding binary path\". It means the runtime could not determine the path of the currently running program.","triggerScenarios":"os.Executable() failing on non-Linux platforms: the executable was deleted or renamed while running (common on macOS/darwin and Windows), the process was started via a mechanism that erased the program path, or an OS API failure returning an error from sysctl/GetModuleFileName.","commonSituations":"Self-upgrading binaries that delete/replace the running executable before calling WriteProfiles; running from an overwritten temp binary; exotic sandbox/container runtimes where the executable path is unavailable.","solutions":["Do not delete or rename the running binary before profile collection completes (keep the old file until after WriteProfiles)","Keep the original executable on disk while the process runs; stage upgrades by copying to a new file and swapping via rename after shutdown","On Linux this path is /proc/<pid>/exe and this specific error cannot occur — verify GOOS if you see it there","Provide a pre-recorded binary path fallback if your deployment deletes executables"],"exampleFix":"// before\nos.Remove(selfPath)      // self-upgrade deletes running binary\nWriteProfiles(ctx, p)    // os.Executable() fails: path gone\n// after\nWriteProfiles(ctx, p)    // collect while binary still exists\nos.Remove(oldBinaryPath) // clean up after profiling","handlingStrategy":"fallback","validationCode":"if runtime.GOOS != \"linux\" {\n    if _, err := os.Executable(); err != nil {\n        log.Printf(\"binary path unavailable, skipping binary embed: %v\", err)\n        return skipBinaryCollector\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := WriteProfiles(ctx, p); err != nil {\n    var pe *fs.PathError\n    if errors.As(errors.Unwrap(err), &pe) && strings.HasPrefix(err.Error(), \"finding binary path\") {\n        log.Printf(\"no executable path; rerun without the binary collector: %v\", pe)\n    }\n    return err\n}","preventionTips":["Never delete or rename the running executable before profile collection finishes","Stage self-upgrades by writing a new file and swapping after shutdown, not by removing the running image","On non-Linux, test that os.Executable() works in your launch environment (launchd, services, containers)","Treat binary embedding as optional and droppable in your diagnostics tooling"],"tags":["diagnostics","os-executable","cross-platform","runtime"],"backgroundTag":"executable-not-found-in-path","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}