{"record":{"id":"953bfde660263b89","repo":"valyala/fasthttp","slug":"prefork-command-producer-w","errorCode":null,"errorMessage":"prefork: command producer: %w","messagePattern":"prefork: command producer: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"prefork/prefork.go","lineNumber":353,"sourceCode":"func childEnv() []string {\n\tsrc := os.Environ()\n\tout := make([]string, 0, len(src)+1)\n\tprefix := preforkChildEnvVariable + \"=\"\n\tfor _, kv := range src {\n\t\tif len(kv) >= len(prefix) && kv[:len(prefix)] == prefix {\n\t\t\tcontinue\n\t\t}\n\t\tout = append(out, kv)\n\t}\n\tout = append(out, preforkChildEnvVariable+\"=\"+preforkChildEnvValue)\n\treturn out\n}\n\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{","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/prefork/prefork.go#L335-L371","documentation":"Returned by Prefork.doCommand when the user-supplied CommandProducer function returns an error. The library delegates child-process construction to this callback and surfaces any failure from it wrapped with this prefix. It is a wrapper around user code, so the root cause is inside the custom CommandProducer.","triggerScenarios":"Prefork.CommandProducer is set and the callback returns a non-nil error when invoked with the listener files (e.g. it fails to build exec.Cmd, validate files, or resolve its own resources).","commonSituations":"Custom CommandProducer logic that reads config/env that is missing in child-spawn contexts; failing exec.LookPath inside the producer; transient resource errors while constructing the command.","solutions":["Inspect the wrapped (%w) cause to find the failure inside your CommandProducer.","Make CommandProducer defensive: validate inputs (files, env) and return clear errors or fall back to a default command.","If the producer cannot produce a command, consider removing it so doCommand uses the default executable path.","Add logging in the producer to capture its internal error before returning it."],"exampleFix":"// before\np.CommandProducer = func(files []*os.File) (*exec.Cmd, error) { return buildCmd(missingCfg) }\n// after\np.CommandProducer = func(files []*os.File) (*exec.Cmd, error) {\n    if err := validateCfg(); err != nil { return nil, fmt.Errorf(\"cfg: %w\", err) }\n    return buildCmd()\n}","handlingStrategy":"try-catch","validationCode":"// Validate the producer before assigning:\np.CommandProducer = func(files []*os.File) (*exec.Cmd, error) {\n    if len(files) == 0 { return nil, errors.New(\"no listener files\") }\n    return buildCmd(files)\n}","typeGuard":null,"tryCatchPattern":"p.CommandProducer = func(files []*os.File) (*exec.Cmd, error) {\n    cmd, err := buildCmd(files)\n    if err != nil {\n        log.Printf(\"command producer failed: %v\", err)\n        return nil, err // wrapped by prefork: command producer: %w\n    }\n    return cmd, nil\n}","preventionTips":["Keep CommandProducer logic simple and side-effect free where possible.","Log the root error inside the producer before returning it.","Test the producer in isolation with fake listener files.","Fall back to default executable behavior when the producer cannot run."],"tags":["go","prefork","command-producer"],"backgroundTag":"custom-callback-failed","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}