{"record":{"id":"ecfdac92cc6e50c4","repo":"valyala/fasthttp","slug":"prefork-resolve-s-s-w","errorCode":null,"errorMessage":"prefork: resolve %s/%s: %w","messagePattern":"prefork: resolve (.+?)/(.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"prefork/prefork.go","lineNumber":309,"sourceCode":"\t}\n\n\tp.ln = ln\n\n\tif p.OnMasterDeath != nil {\n\t\tgo p.watchMaster(os.Getppid())\n\t}\n\n\treturn ln, nil\n}\n\nfunc (p *Prefork) setTCPListenerFiles(addr string) error {\n\tif p.Network == \"\" {\n\t\tp.Network = defaultNetwork\n\t}\n\n\ttcpAddr, err := net.ResolveTCPAddr(p.Network, addr)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"prefork: resolve %s/%s: %w\", p.Network, addr, err)\n\t}\n\n\ttcpListener, err := net.ListenTCP(p.Network, tcpAddr)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"prefork: listen tcp %s: %w\", addr, err)\n\t}\n\n\tlistenerFile, err := tcpListenerFile(tcpListener)\n\tif err != nil {\n\t\t// Close the bound listener so we don't leak the socket/fd when\n\t\t// File() fails. p.ln is intentionally only assigned after this\n\t\t// point so the caller never sees a half-initialised state.\n\t\t_ = tcpListener.Close()\n\t\treturn fmt.Errorf(\"prefork: dup listener fd: %w\", err)\n\t}\n\n\tp.ln = tcpListener\n\tp.files = []*os.File{listenerFile}","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/prefork/prefork.go#L291-L327","documentation":"In prefork's setTCPListenerFiles, net.ResolveTCPAddr failed to resolve the given address with the configured network (tcp/tcp4/tcp6). The error is wrapped as 'prefork: resolve <network>/<addr>'. This happens before any socket is created, so it is a pure address/network resolution failure — bad address literal, unsupported network string, or unresolvable host.","triggerScenarios":"Calling fasthttp Prefork with an addr like \":port\", \"localhost:8080\", or a malformed literal (\":::8080\") when ResolveTCPAddr rejects it; p.Network set to an unsupported value.","commonSituations":"Config typo in the listen address; passing a hostname where the environment lacks DNS; mixing \"tcp6\" network with an IPv4 address; empty address parsing failures.","solutions":["Fix the listen address to a valid literal like \":8080\" or \"0.0.0.0:8080\"; verify with net.ResolveTCPAddr(p.Network, addr) in isolation.","Match the network to the address: use \"tcp\" (default) unless you need tcp4/tcp6, and use an IPv6 literal with tcp6.","If using a hostname, ensure DNS resolution works in the environment, or replace it with an IP literal.","Check the prefork Network configuration isn't overwritten (e.g. set to \"unix\") before setTCPListenerFiles runs."],"exampleFix":"// before\np.Network = \"tcp6\"\naddr := \"0.0.0.0:8080\" // IPv4 literal with tcp6 -> resolve error\n// after\np.Network = \"tcp\"\naddr := \":8080\"","handlingStrategy":"validation","validationCode":"// Validate the prefork address/network before starting:\nfunc validatePreforkAddr(network, addr string) error {\n    if network == \"\" { network = \"tcp\" }\n    switch network {\n    case \"tcp\", \"tcp4\", \"tcp6\":\n    default:\n        return fmt.Errorf(\"unsupported prefork network %q\", network)\n    }\n    if _, err := net.ResolveTCPAddr(network, addr); err != nil {\n        return fmt.Errorf(\"invalid prefork addr %s/%s: %w\", network, addr, err)\n    }\n    return nil\n}","typeGuard":"func isResolveError(err error) bool {\n    return err != nil && strings.HasPrefix(err.Error(), \"prefork: resolve \")\n}","tryCatchPattern":"if err := validatePreforkAddr(p.Network, addr); err != nil {\n    return fmt.Errorf(\"startup aborted: %w\", err) // fail fast, before Prefork\n}\nif err := fasthttp.Prefork(...); err != nil {\n    if strings.HasPrefix(err.Error(), \"prefork: resolve \") {\n        log.Printf(\"bad prefork address: %v\", err)\n    }\n    return err\n}","preventionTips":["Use literal addresses (\":8080\", \"0.0.0.0:8080\") for prefork listeners.","Match network (tcp/tcp4/tcp6) to the address family, or leave Network empty for the default.","Resolve addresses in config validation before launching the server.","Don't pass unix-socket networks into setTCPListenerFiles; that path is TCP-only."],"tags":["fasthttp","prefork","tcp","address-resolution"],"backgroundTag":"address-resolution-failed","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}