gofiber/fiber · error
remote address cannot be empty
Error message
remote address cannot be empty
What it means
Returned by middleware/adaptor.resolveRemoteAddr when the remoteAddr argument is the empty string. resolveRemoteAddr converts a net/http-style RemoteAddr into a net.Addr when bridging requests into Fiber; an empty address cannot be turned into a meaningful TCP/Unix peer. The check runs before any parsing so malformed input fails fast rather than reaching the resolver.
Solutions
- Ensure the inbound request carries a populated RemoteAddr ("ip:port") before it reaches the adaptor conversion path.
- If you control the caller, default RemoteAddr to a known sentinel (e.g. "127.0.0.1:0") for synthetic requests.
- Guard the conversion: skip resolveRemoteAddr when RemoteAddr is empty and proceed without peer info.
Example fix
// before
addr, err := resolveRemoteAddr(r.RemoteAddr, nil)
// after
remote := r.RemoteAddr
if remote == "" {
remote = "127.0.0.1:0"
}
addr, err := resolveRemoteAddr(remote, nil) Defensive patterns
Strategy: validation
Validate before calling
if r.RemoteAddr == "" {
r.RemoteAddr = "127.0.0.1:0" // synthetic peer for in-process requests
} Try / catch
addr, err := adaptor.ResolveRemoteAddr(remote, local)
if err != nil {
if errors.Is(err, adaptor.ErrRemoteAddrEmpty) {
// proceed without a peer addr, or log and reject
}
return err
} Prevention
- Treat RemoteAddr as required input for any net/http -> Fiber conversion path.
- In tests, always set http.Request.RemoteAddr to a synthetic value.
- Validate upstream request shape at the trust boundary before adapting.
When it happens
Trigger: Calling an adaptor helper that resolves the peer address (e.g. when converting a net/http request whose RemoteAddr field was never populated) with an empty string. Happens with in-process clients or test harnesses that build a fake http.Request without setting RemoteAddr.
Common situations: Unit tests constructing http.Request{} manually; a reverse proxy that strips peer info before the request reaches the adaptor; an internal pipeline request that has no real socket peer.
Related errors
- failed to resolve TCP address after adding port
- failed to resolve TCP address
- cache: failed to delete key
- cache: failed to get key
- cache: failed to get raw key
AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11).
Data as JSON: /api/errors/d965562a413a5a4a.
Report an issue: GitHub.
Appendix: source
Thrown at middleware/adaptor/adaptor.go:222
dst[key] = append(existing, val)
continue
}
if vals == nil {
vals = make([]string, 0, count)
} else if len(vals) == cap(vals) {
dst[key] = []string{val}
continue
}
i := len(vals)
vals = append(vals, val)
dst[key] = vals[i : i+1 : i+1]
}
}
var (
ErrRemoteAddrEmpty = errors.New("remote address cannot be empty")
ErrRemoteAddrTooLong = errors.New("remote address too long")
)
// HTTPHandlerFunc wraps net/http handler func to fiber handler
func HTTPHandlerFunc(h http.HandlerFunc) fiber.Handler {
return HTTPHandler(h)
}
// HTTPHandler wraps net/http handler to fiber handler
func HTTPHandler(h http.Handler) fiber.Handler {
handler := fasthttpadaptor.NewFastHTTPHandler(h)
return func(c fiber.Ctx) error {
handler(c.RequestCtx())
return nil
}
}
// HTTPHandlerWithContext is like HTTPHandler, but additionally stores Fiber’s user context in the request contextView on GitHub (pinned to a105acad6c)