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

  1. Ensure the inbound request carries a populated RemoteAddr ("ip:port") before it reaches the adaptor conversion path.
  2. If you control the caller, default RemoteAddr to a known sentinel (e.g. "127.0.0.1:0") for synthetic requests.
  3. 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

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


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 context

View on GitHub (pinned to a105acad6c)