valyala/fasthttp · warning

fasthttp: cannot serve the connection because server.concurr

Error message

fasthttp: cannot serve the connection because server.concurrency concurrent connections are served

What it means

ErrConcurrencyLimit may be returned from Server.ServeConn when the number of concurrently served connections reaches Server.Concurrency. Fasthttp accepts the connection but refuses to serve it because the global concurrency budget is exhausted.

Source

Thrown at server.go:2203

}

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 {
		pic := wrapPerIPConn(s, c)
		if pic == nil {
			return ErrPerIPConnLimit
		}

View on GitHub (pinned to c96f600972)

Solutions

  1. Increase Server.Concurrency to match expected peak load (or 0 for unlimited).
  2. Shorten handler durations / add timeouts (ReadTimeout, WriteTimeout) so connections free up faster.
  3. Scale horizontally or put a load balancer in front to spread connections.

Example fix

// before
srv := &fasthttp.Server{Handler: h, Concurrency: 16}
// after
srv := &fasthttp.Server{Handler: h, Concurrency: 0} // unlimited, or a larger bound
Defensive patterns

Strategy: retry

Validate before calling

if srv.Concurrency > 0 && srv.Concurrency < peakExpectedConns {
    srv.Concurrency = peakExpectedConns // or 0 for unlimited
}

Prevention

When it happens

Trigger: Server.Concurrency > 0 and the server already has Concurrency connections being served when a new connection arrives at ServeConn.

Common situations: Slow clients or slow handlers holding connections open, exhausting the pool; load spikes beyond the configured Concurrency; Concurrency intentionally set very low and forgotten.

Related errors


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