{"record":{"id":"954d26f75086dbc5","repo":"valyala/fasthttp","slug":"fasthttp-cannot-serve-the-connection-because-serv","errorCode":null,"errorMessage":"fasthttp: cannot serve the connection because server.concurrency concurrent connections are served","messagePattern":"fasthttp: cannot serve the connection because server\\.concurrency concurrent connections are served","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server.go","lineNumber":2203,"sourceCode":"}\n\nvar defaultLogger = Logger(log.New(os.Stderr, \"\", log.LstdFlags))\n\nfunc (s *Server) logger() Logger {\n\tif s.Logger != nil {\n\t\treturn s.Logger\n\t}\n\treturn defaultLogger\n}\n\nvar (\n\t// ErrPerIPConnLimit may be returned from ServeConn if the number of connections\n\t// per ip exceeds Server.MaxConnsPerIP.\n\tErrPerIPConnLimit = errors.New(\"fasthttp: too many connections per ip\")\n\n\t// ErrConcurrencyLimit may be returned from ServeConn if the number\n\t// of concurrently served connections exceeds Server.Concurrency.\n\tErrConcurrencyLimit = errors.New(\"fasthttp: cannot serve the connection because server.concurrency \" +\n\t\t\"concurrent connections are served\")\n)\n\n// ServeConn serves HTTP requests from the given connection.\n//\n// ServeConn returns nil if all requests from the c are successfully served.\n// It returns non-nil error otherwise.\n//\n// Connection c must immediately propagate all the data passed to Write()\n// to the client. Otherwise requests' processing may hang.\n//\n// ServeConn closes c before returning.\nfunc (s *Server) ServeConn(c net.Conn) error {\n\tif s.MaxConnsPerIP > 0 {\n\t\tpic := wrapPerIPConn(s, c)\n\t\tif pic == nil {\n\t\t\treturn ErrPerIPConnLimit\n\t\t}","sourceCodeStart":2185,"sourceCodeEnd":2221,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/server.go#L2185-L2221","documentation":"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.","triggerScenarios":"Server.Concurrency > 0 and the server already has Concurrency connections being served when a new connection arrives at ServeConn.","commonSituations":"Slow clients or slow handlers holding connections open, exhausting the pool; load spikes beyond the configured Concurrency; Concurrency intentionally set very low and forgotten.","solutions":["Increase Server.Concurrency to match expected peak load (or 0 for unlimited).","Shorten handler durations / add timeouts (ReadTimeout, WriteTimeout) so connections free up faster.","Scale horizontally or put a load balancer in front to spread connections."],"exampleFix":"// before\nsrv := &fasthttp.Server{Handler: h, Concurrency: 16}\n// after\nsrv := &fasthttp.Server{Handler: h, Concurrency: 0} // unlimited, or a larger bound","handlingStrategy":"retry","validationCode":"if srv.Concurrency > 0 && srv.Concurrency < peakExpectedConns {\n    srv.Concurrency = peakExpectedConns // or 0 for unlimited\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set Concurrency deliberately (0 = unlimited) rather than leaving a small default.","Keep handler latency low and apply WriteTimeout/ReadTimeout so connections recycle.","Add client-side retry with backoff on this error (it is load-dependent and transient).","Alert on active-connection count nearing Concurrency."],"tags":["server","concurrency","backpressure"],"backgroundTag":"server-concurrency-limit-reached","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}