valyala/fasthttp · warning

fasthttp: too many connections per ip

Error message

fasthttp: too many connections per ip

What it means

ErrPerIPConnLimit may be returned from Server.ServeConn when the number of concurrently open connections from a single client IP exceeds Server.MaxConnsPerIP. It is a deliberate rate-guard against a single host monopolizing the server.

Source

Thrown at server.go:2199

		c.Close()
		return nil
	}
	return acquirePerIPConn(c, ip, &s.perIPConnCounter)
}

var defaultLogger = Logger(log.New(os.Stderr, "", log.LstdFlags))

func (s *Server) logger() Logger {
	if s.Logger != nil {
		return s.Logger
	}
	return defaultLogger
}

var (
	// ErrPerIPConnLimit may be returned from ServeConn if the number of connections
	// per ip exceeds Server.MaxConnsPerIP.
	ErrPerIPConnLimit = errors.New("fasthttp: too many connections per ip")

	// ErrConcurrencyLimit may be returned from ServeConn if the number
	// of concurrently served connections exceeds Server.Concurrency.
	ErrConcurrencyLimit = errors.New("fasthttp: cannot serve the connection because server.concurrency " +
		"concurrent connections are served")
)

// ServeConn serves HTTP requests from the given connection.
//
// ServeConn returns nil if all requests from the c are successfully served.
// It returns non-nil error otherwise.
//
// Connection c must immediately propagate all the data passed to Write()
// to the client. Otherwise requests' processing may hang.
//
// ServeConn closes c before returning.
func (s *Server) ServeConn(c net.Conn) error {
	if s.MaxConnsPerIP > 0 {

View on GitHub (pinned to c96f600972)

Solutions

  1. Raise Server.MaxConnsPerIP to a value suitable for your traffic (including NAT'd users).
  2. Set MaxConnsPerIP to 0 to disable per-IP limiting if it's not needed.
  3. Have clients use connection pooling / keep-alive instead of opening many concurrent connections.

Example fix

// before
srv := &fasthttp.Server{Handler: h, MaxConnsPerIP: 2}
// after
srv := &fasthttp.Server{Handler: h, MaxConnsPerIP: 100} // or 0 to disable
Defensive patterns

Strategy: retry

Validate before calling

if srv.MaxConnsPerIP > 0 && srv.MaxConnsPerIP < expectedConnsPerClient {
    // raise the limit before serving
    srv.MaxConnsPerIP = expectedConnsPerClient
}

Prevention

When it happens

Trigger: A client (or NAT'd group of clients sharing one IP) opens more simultaneous TCP connections than MaxConnsPerIP allows while the server accepts the connection and calls ServeConn.

Common situations: Corporate proxies/NAT aggregating many users behind one IP; load tests from a single machine with low MaxConnsPerIP; misconfigured MaxConnsPerIP set too low for legitimate traffic.

Related errors


AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31). Data as JSON: /api/errors/3315b66ff031e669. Report an issue: GitHub.