{"record":{"id":"abd0b523081de13a","repo":"gofiber/fiber","slug":"prefork-w","errorCode":null,"errorMessage":"prefork: %w","messagePattern":"prefork: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"prefork.go","lineNumber":116,"sourceCode":"\t\t}\n\t\treturn nil\n\t}\n\n\t// Master callback: all children spawned → startup message & OnListen hooks\n\tp.OnMasterReady = func(childPIDs []int) error {\n\t\tlistenData := app.prepareListenData(addr, tlsConfig != nil, cfg, childPIDs)\n\t\tapp.runOnListenHooks(listenData)\n\t\tapp.printMessages(cfg, listenData)\n\t\treturn nil\n\t}\n\n\t// Master callback: child recovered after crash\n\tp.OnChildRecover = func(oldPID, newPID int) {\n\t\tlogger.Printf(\"prefork: child %d crashed, recovered with new PID %d\", oldPID, newPID)\n\t}\n\n\tif err := p.ListenAndServe(addr); err != nil {\n\t\treturn fmt.Errorf(\"prefork: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// dummyCmd is for internal prefork testing\nfunc dummyCmd() *exec.Cmd {\n\tcommand := \"go\"\n\tif storeCommand := dummyChildCmd.Load(); storeCommand != nil && storeCommand != \"\" {\n\t\tcommand = storeCommand.(string) //nolint:forcetypeassert,errcheck // We always store a string in here\n\t}\n\tif runtime.GOOS == windowsOS {\n\t\treturn exec.Command(\"cmd\", \"/C\", command, \"version\")\n\t}\n\treturn exec.Command(command, \"version\")\n}\n","sourceCodeStart":98,"sourceCodeEnd":133,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/prefork.go#L98-L133","documentation":"Thrown when the prefork master process's ListenAndServe(addr) fails. Prefork uses SO_REUSEPORT to run multiple child listeners; the master must itself bind the address. The %w wraps the underlying listener/bind error. This is fatal to server startup — if the master cannot listen, no children serve.","triggerScenarios":"The address is already bound by another process (EADDRINUSE); binding a privileged port (<1024) without sufficient privileges (EACCES); SO_REUSEPORT unsupported on the platform/older kernel; an invalid/already-resolved address; listener creation failure; the network value in ListenConfig is invalid.","commonSituations":"Another server already on the port; running as non-root on :80/:443; older Windows or kernels without SO_REUSEPORT; misformed host:port in app.Listen(..., prefork); running inside a container whose port is already bound at the host level.","solutions":["Free or change the port (the wrapped error is usually EADDRINUSE / EACCES — read it).","Run with privileges for ports <1024, or use a non-privileged port plus setcap/sudo/iptables redirect.","Disable prefork on platforms without SO_REUSEPORT support.","Validate the address format and ListenerNetwork before calling Listen with Prefork: true.","Check the container/host port binding."],"exampleFix":"// before\napp.Listen(\":80\", fiber.ListenConfig{Prefork: true}) // EACCES or EADDRINUSE -> prefork: ...\n\n// after\naddr := \":8080\"\nln, err := net.Listen(\"tcp\", addr)\nif err != nil { log.Fatalf(\"cannot bind %s: %v\", addr, err) }\nln.Close()\napp.Listen(addr, fiber.ListenConfig{Prefork: true})","handlingStrategy":"validation","validationCode":"// Probe-bind before starting prefork to get a clear, early failure.\nfunc checkListen(addr, network string) error {\n    ln, err := net.Listen(network, addr)\n    if err != nil { return err }\n    return ln.Close()\n}\n// also guard privileges for low ports\nfunc canBindLowPort(port int) bool {\n    return port >= 1024 || os.Geteuid() == 0\n}","typeGuard":"func addrLikelyBindable(addr string) bool {\n    _, portStr, err := net.SplitHostPort(addr)\n    if err != nil { return false }\n    port, _ := strconv.Atoi(portStr)\n    return port >= 1024 || os.Geteuid() == 0\n}","tryCatchPattern":"if err := checkListen(addr, cfg.ListenerNetwork); err != nil {\n    log.Fatalf(\"prefork pre-bind check failed for %s: %v\", addr, err)\n}\nif err := app.Listen(addr, fiber.ListenConfig{Prefork: true}); err != nil {\n    log.Fatalf(\"prefork: %v\", err)\n}","preventionTips":["Probe-bind the address before starting prefork to surface EADDRINUSE/EACCES early.","Avoid privileged ports unless the process has CAP_NET_BIND_SERVICE / runs as root.","Do not enable Prefork on platforms without SO_REUSEPORT.","Confirm the container/host port is free."],"tags":["prefork","network","startup","bind","reuseport"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}