{"record":{"id":"33eab4d63bd46196","repo":"valyala/fasthttp","slug":"prefork-exceeding-the-value-of-recoverthreshold","errorCode":null,"errorMessage":"prefork: exceeding the value of recoverthreshold","messagePattern":"prefork: exceeding the value of recoverthreshold","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"prefork/prefork.go","lineNumber":48,"sourceCode":"\n\t// masterPollInterval is the period of the watchMaster ppid-poll on Unix.\n\tmasterPollInterval = 500 * time.Millisecond\n\n\t// defaultShutdownGracePeriod is how long the master waits for children to\n\t// exit cleanly after sending SIGTERM before forcibly killing them.\n\tdefaultShutdownGracePeriod = 5 * time.Second\n)\n\nvar (\n\tdefaultLogger = Logger(log.New(os.Stderr, \"\", log.LstdFlags))\n\n\t// tcpListenerFile is a hook for (*net.TCPListener).File so tests can\n\t// inject failure paths without binding a real socket.\n\ttcpListenerFile = (*net.TCPListener).File\n\n\t// ErrOverRecovery is returned when child prefork process restarts exceed\n\t// the value of RecoverThreshold.\n\tErrOverRecovery = errors.New(\"prefork: exceeding the value of recoverthreshold\")\n\n\t// ErrOnlyReuseportOnWindows is returned when running on Windows without Reuseport.\n\tErrOnlyReuseportOnWindows = errors.New(\"prefork: windows only supports reuseport = true\")\n\n\t// ErrCommandProducerNilCmd is returned when a CommandProducer returns\n\t// (nil, nil) instead of a started command.\n\tErrCommandProducerNilCmd = errors.New(\"prefork: commandproducer returned nil command\")\n\n\t// ErrCommandProducerNotStarted is returned when a CommandProducer returns\n\t// an *exec.Cmd whose Process is nil (i.e. cmd.Start() was not called).\n\tErrCommandProducerNotStarted = errors.New(\"prefork: commandproducer must return a started command\")\n)\n\n// Logger is used for logging formatted messages. Its method set is intentionally\n// identical to fasthttp.Logger so that *fasthttp.Server.Logger can be assigned\n// directly.\ntype Logger interface {\n\t// Printf must have the same semantics as log.Printf.","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/prefork/prefork.go#L30-L66","documentation":"In prefork mode, the parent supervises child processes; if a child keeps dying and the number of restarts exceeds RecoverThreshold, prefork gives up and returns ErrOverRecovery to avoid an infinite crash-restart loop.","triggerScenarios":"Running prefork.Listen/Run where a child process repeatedly crashes on startup (bind failure, fatal handler error) more times than RecoverThreshold within the recovery window.","commonSituations":"Port already in use causing every child to fail binding; a panic during app initialization (bad config, missing env); setting RecoverThreshold too low for legitimately flaky environments.","solutions":["Fix the underlying child crash first: check logs — typically port conflicts (SO_REUSEPORT/port in use) or panics during app setup.","Raise prefork.Options.RecoverThreshold (and/or RecoverInterval) if restarts are expected to be transient.","Verify Reuseport settings and that the listening address is free before enabling prefork."],"exampleFix":"// before\npf := prefork.New(app) // default RecoverThreshold\nerr := pf.Listen(\":8080\") // children crash-loop -> ErrOverRecovery\n// after\npf := prefork.New(app)\npf.RecoverThreshold = 10\n// and fix the child crash (e.g. free port :8080)\nerr := pf.Listen(\":8080\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := pf.Listen(\":8080\")\nif errors.Is(err, prefork.ErrOverRecovery) {\n    log.Fatal(\"children keep crashing past RecoverThreshold; check port conflicts and startup panics\")\n}","preventionTips":["Smoke-test the app in non-prefork mode first so child crashes surface clearly.","Ensure the port is free and Reuseport is configured correctly.","Set RecoverThreshold/RecoverInterval appropriate to your environment."],"tags":["prefork","process-management","crash-loop"],"backgroundTag":"crash-loop-threshold-exceeded","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}