{"id":"d965562a413a5a4a","repo":"gofiber/fiber","slug":"remote-address-cannot-be-empty","errorCode":null,"errorMessage":"remote address cannot be empty","messagePattern":"remote address cannot be empty","errorType":"validation","errorClass":"ErrRemoteAddrEmpty","httpStatus":null,"severity":"error","filePath":"middleware/adaptor/adaptor.go","lineNumber":221,"sourceCode":"\t\t\tdst[key] = append(existing, val)\n\t\t\tcontinue\n\t\t}\n\n\t\tif vals == nil {\n\t\t\tvals = make([]string, 0, count)\n\t\t} else if len(vals) == cap(vals) {\n\t\t\tdst[key] = []string{val}\n\t\t\tcontinue\n\t\t}\n\n\t\ti := len(vals)\n\t\tvals = append(vals, val)\n\t\tdst[key] = vals[i : i+1 : i+1]\n\t}\n}\n\nvar (\n\tErrRemoteAddrEmpty   = errors.New(\"remote address cannot be empty\")\n\tErrRemoteAddrTooLong = errors.New(\"remote address too long\")\n)\n\n// HTTPHandlerFunc wraps net/http handler func to fiber handler\nfunc HTTPHandlerFunc(h http.HandlerFunc) fiber.Handler {\n\treturn HTTPHandler(h)\n}\n\n// HTTPHandler wraps net/http handler to fiber handler\nfunc HTTPHandler(h http.Handler) fiber.Handler {\n\thandler := fasthttpadaptor.NewFastHTTPHandler(h)\n\treturn func(c fiber.Ctx) error {\n\t\thandler(c.RequestCtx())\n\t\treturn nil\n\t}\n}\n\n// HTTPHandlerWithContext is like HTTPHandler, but additionally stores Fiber’s user context in the request context","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/middleware/adaptor/adaptor.go#L203-L239","documentation":"Returned by adaptor.resolveRemoteAddr when the remote address string passed to it is empty. The adaptor bridges net/http handlers onto Fiber's fasthttp runtime and needs a valid RemoteAddr to construct a net.Addr for the request. An empty string means the underlying server never populated the peer address (e.g. a custom listener or a manually constructed RequestCtx). The check lives at adaptor.go:422-424 and short-circuits before any parsing.","triggerScenarios":"Calling adaptor.HTTPHandler / HTTPMiddleware with a fiber.Ctx whose RequestCtx has an empty RemoteAddr — typically when the request arrives over a Unix socket listener where localAddr resolves via isUnixNetwork but the fallback path is skipped, or when tests invoke a handler with a hand-built RequestCtx that never had RemoteAddr set. resolveRemoteAddr is invoked during net/http adaptation when the adapted handler reads r.RemoteAddr.","commonSituations":"Unit/integration tests that construct fasthttp.RequestCtx manually without setting RemoteAddr; custom transport wrappers (e.g. wrapping FiberApp behind another server) that strip the address; misconfigured Unix-socket listeners where the network check fails to match. Also seen when upgrading Fiber versions that changed how RemoteAddr is propagated.","solutions":["Ensure the underlying listener populates RemoteAddr — use a standard net.Listener or Fiber's built-in Listen that sets it automatically.","If running over a Unix socket, verify isUnixNetwork recognizes 'unix'/'unixgram'/'unixpacket' so the localAddr fast path is taken instead of requiring remoteAddr.","In tests, set ctx.RequestCtx().RemoteAddr = ... before invoking the adapted handler.","If you wrapped the listener, propagate the peer address in your wrapper's Accept loop."],"exampleFix":"// before (test): ctx is a *fasthttp.RequestCtx with no address\nhandler(ctx)\n// after\nctx.RemoteAddr = &net.TCPAddr{IP: net.IPv4(127,0,0,1), Port: 1234}\nhandler(ctx)","handlingStrategy":"validation","validationCode":"// Before adapting, confirm the request context has a remote address\nrc := c.RequestCtx()\nif utils.UnsafeString(rc.RemoteAddr().String()) == \"\" {\n    // set a placeholder or reject before calling the adapted handler\n    return fiber.ErrBadRequest\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use Fiber's built-in Listen helpers which populate RemoteAddr automatically.","In tests, set ctx.RemoteAddr before invoking adapted handlers.","For Unix socket listeners, verify the network type string matches 'unix'/'unixgram'/'unixpacket'."],"tags":["adaptor","network","configuration","net-http"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}