gofiber/fiber · error · ErrRemoteAddrEmpty

remote address cannot be empty

Error message

remote address cannot be empty

What it means

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.

Source

Thrown at middleware/adaptor/adaptor.go:221

			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 9a4c7e57fe)

Solutions

  1. Ensure the underlying listener populates RemoteAddr — use a standard net.Listener or Fiber's built-in Listen that sets it automatically.
  2. If running over a Unix socket, verify isUnixNetwork recognizes 'unix'/'unixgram'/'unixpacket' so the localAddr fast path is taken instead of requiring remoteAddr.
  3. In tests, set ctx.RequestCtx().RemoteAddr = ... before invoking the adapted handler.
  4. If you wrapped the listener, propagate the peer address in your wrapper's Accept loop.

Example fix

// before (test): ctx is a *fasthttp.RequestCtx with no address
handler(ctx)
// after
ctx.RemoteAddr = &net.TCPAddr{IP: net.IPv4(127,0,0,1), Port: 1234}
handler(ctx)
Defensive patterns

Strategy: validation

Validate before calling

// Before adapting, confirm the request context has a remote address
rc := c.RequestCtx()
if utils.UnsafeString(rc.RemoteAddr().String()) == "" {
    // set a placeholder or reject before calling the adapted handler
    return fiber.ErrBadRequest
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04). Data as JSON: /data/errors/d965562a413a5a4a.json. Report an issue: GitHub.