{"id":"dce58a8fdbe7fec0","repo":"gofiber/fiber","slug":"failed-to-resolve-tcp-address-w","errorCode":null,"errorMessage":"failed to resolve TCP address: %w","messagePattern":"failed to resolve TCP address: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"middleware/adaptor/adaptor.go","lineNumber":460,"sourceCode":"\n\tresolved, err := net.ResolveTCPAddr(\"tcp\", remoteAddr)\n\tif err == nil {\n\t\treturn resolved, nil\n\t}\n\n\tvar addrErr *net.AddrError\n\tif errors.As(err, &addrErr) && addrErr != nil && addrErr.Err == \"missing port in address\" {\n\t\tif len(remoteAddr) > 253 { // Max hostname length\n\t\t\treturn nil, ErrRemoteAddrTooLong\n\t\t}\n\t\tremoteAddr = net.JoinHostPort(remoteAddr, \"80\")\n\t\tresolved, err2 := net.ResolveTCPAddr(\"tcp\", remoteAddr)\n\t\tif err2 != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to resolve TCP address after adding port: %w\", err2)\n\t\t}\n\t\treturn resolved, nil\n\t}\n\treturn nil, fmt.Errorf(\"failed to resolve TCP address: %w\", err)\n}\n\nfunc handlerFunc(app *fiber.App, h ...fiber.Handler) http.HandlerFunc {\n\t// App.Config returns the config by value, so read the body limit once at\n\t// construction instead of copying the whole 624-byte struct on every\n\t// request. Fiber only writes app.config in New. The error handler is\n\t// deliberately not cached: App.ErrorHandler resolves a mounted sub-app's\n\t// handler from the request path, and that lookup belongs per request.\n\tmaxBodySize := int64(app.Config().BodyLimit)\n\n\treturn func(w http.ResponseWriter, r *http.Request) {\n\t\t// New fasthttp Ctx from pool\n\t\tpctx := ctxPool.Get().(*pooledCtx) //nolint:forcetypeassert,errcheck // not needed\n\t\tfctx := &pctx.fctx\n\t\tfctx.Response.Reset()\n\t\tfctx.Request.Reset()\n\t\tdefer ctxPool.Put(pctx)\n","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/middleware/adaptor/adaptor.go#L442-L478","documentation":"The general failure path in resolveRemoteAddr: net.ResolveTCPAddr('tcp', remoteAddr) failed and the error was not the specific 'missing port in address' case that triggers the add-port retry. Covers malformed addresses, out-of-range ports, DNS lookup failures, and unknown address families. Like the add-port variant it is non-fatal for the request — remoteAddr becomes nil and the handler continues.","triggerScenarios":"Passing adaptor.FiberApp a request whose RemoteAddr is syntactically broken (e.g. '1.2.3.4:99999' — port out of range, 'not a host', or an IPv6 literal without brackets). Also fires when a hostname RemoteAddr cannot be resolved because DNS is unavailable in the current environment.","commonSituations":"IPv6 address without bracketed form ('::1:80' instead of '[::1]:80'); port > 65535 from a misconfigured proxy; ephemeral test containers with no DNS resolver; a TLS-terminating proxy that drops the port when forwarding.","solutions":["Normalize RemoteAddr to host:port form before it reaches the adapter; for IPv6 use bracketed form: net.JoinHostPort(host, port).","Validate the address at your trust boundary (proxy/gateway) and reject/drop malformed X-Forwarded-For.","If the value is a bare IP, append the well-known port yourself before delegating to the fiber adapter.","Ensure DNS resolution works inside the container/host when RemoteAddr carries hostnames (configure /etc/resolv.conf or the resolver)."],"exampleFix":"// before: IPv6 without brackets -> 'cannot parse address'\nr.RemoteAddr = \"::1:80\"\n\n// after: bracketed IPv6 host:port via JoinHostPort\nr.RemoteAddr = net.JoinHostPort(\"::1\", \"80\") // -> \"[::1]:80\"","handlingStrategy":"validation","validationCode":"// Validate RemoteAddr syntax before delegating to the fiber adapter.\nfunc validRemoteAddr(addr string) bool {\n    if addr == \"\" {\n        return false\n    }\n    host, port, err := net.SplitHostPort(addr)\n    if err != nil {\n        return false\n    }\n    p, err := strconv.Atoi(port)\n    return err == nil && p > 0 && p < 65536 && host != \"\"\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Always build addresses with net.JoinHostPort (handles IPv6 bracketing).","Validate port range (1..65535) at the proxy boundary.","Ensure DNS resolver is available in the container/host when hostnames appear.","Unit-test address parsing against IPv4, IPv6, and hostname inputs."],"tags":["adaptor","http","network","remote-addr","ipv6"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}