{"record":{"id":"75c851d05cc60a73","repo":"valyala/fasthttp","slug":"prefork-resolve-executable-w","errorCode":null,"errorMessage":"prefork: resolve executable: %w","messagePattern":"prefork: resolve executable: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"prefork/prefork.go","lineNumber":366,"sourceCode":"\nfunc (p *Prefork) doCommand() (*exec.Cmd, error) {\n\tif p.CommandProducer != nil {\n\t\tcmd, err := p.CommandProducer(p.files)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"prefork: command producer: %w\", err)\n\t\t}\n\t\tif cmd == nil {\n\t\t\treturn nil, ErrCommandProducerNilCmd\n\t\t}\n\t\tif cmd.Process == nil {\n\t\t\treturn nil, ErrCommandProducerNotStarted\n\t\t}\n\t\treturn cmd, nil\n\t}\n\n\texecutable, err := os.Executable()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"prefork: resolve executable: %w\", err)\n\t}\n\n\targs := append([]string{executable}, os.Args[1:]...)\n\n\tcmd := &exec.Cmd{\n\t\tPath:       executable,\n\t\tArgs:       args,\n\t\tStdout:     os.Stdout,\n\t\tStderr:     os.Stderr,\n\t\tEnv:        childEnv(),\n\t\tExtraFiles: p.files,\n\t}\n\tif err = cmd.Start(); err != nil {\n\t\treturn nil, fmt.Errorf(\"prefork: start child %q: %w\", executable, err)\n\t}\n\treturn cmd, nil\n}\n","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/prefork/prefork.go#L348-L384","documentation":"Returned by Prefork.doCommand when os.Executable() fails to resolve the path of the current executable, which prefork needs to re-exec itself as the child process. This indicates the running binary's path could not be determined by the OS/runtime.","triggerScenarios":"Calling prefork in an environment where /proc/self/exe is unavailable (Linux procfs not mounted), the binary was deleted after start, or the runtime cannot read /proc (e.g. minimal containers, some chroots).","commonSituations":"Distroless/minimal containers without /proc mounted properly; binary replaced/deleted while running (deleted-file /proc/self/exe pointing to '(deleted)'); running under exotic sandboxes (gVisor misconfigurations).","solutions":["Ensure /proc is mounted in the container (mount -t proc proc /proc).","Do not delete/overwrite the running binary; deploy atomically (write new file, rename, restart).","Run prefork in a normal OS environment rather than a heavily restricted chroot.","If unavoidable, set a custom CommandProducer that supplies the executable path directly."],"exampleFix":"// before\n# Dockerfile FROM scratch without /proc handling, binary deleted mid-run\n// after\n# keep the binary on disk; use multi-stage copy and full restarts:\nCOPY app /app/app\nENTRYPOINT [\"/app/app\"]","handlingStrategy":"validation","validationCode":"// Pre-flight: ensure os.Executable works in this environment\nif _, err := os.Executable(); err != nil {\n    log.Fatalf(\"cannot resolve executable path: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := p.Listen(addr); err != nil {\n    if strings.Contains(err.Error(), \"resolve executable\") {\n        log.Fatalf(\"environment cannot resolve /proc/self/exe: %v\", err)\n    }\n    log.Fatal(err)\n}","preventionTips":["Mount /proc in containers.","Never delete or overwrite a running binary; deploy with atomic rename + restart.","Set a custom CommandProducer if the environment cannot resolve executables.","Smoke-test prefork startup in the target container image."],"tags":["go","prefork","executable-path"],"backgroundTag":"os-executable-resolution-failed","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}