{"record":{"id":"3315b66ff031e669","repo":"valyala/fasthttp","slug":"fasthttp-too-many-connections-per-ip","errorCode":null,"errorMessage":"fasthttp: too many connections per ip","messagePattern":"fasthttp: too many connections per ip","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server.go","lineNumber":2199,"sourceCode":"\t\tc.Close()\n\t\treturn nil\n\t}\n\treturn acquirePerIPConn(c, ip, &s.perIPConnCounter)\n}\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 {","sourceCodeStart":2181,"sourceCodeEnd":2217,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/server.go#L2181-L2217","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Raise Server.MaxConnsPerIP to a value suitable for your traffic (including NAT'd users).","Set MaxConnsPerIP to 0 to disable per-IP limiting if it's not needed.","Have clients use connection pooling / keep-alive instead of opening many concurrent connections."],"exampleFix":"// before\nsrv := &fasthttp.Server{Handler: h, MaxConnsPerIP: 2}\n// after\nsrv := &fasthttp.Server{Handler: h, MaxConnsPerIP: 100} // or 0 to disable","handlingStrategy":"retry","validationCode":"if srv.MaxConnsPerIP > 0 && srv.MaxConnsPerIP < expectedConnsPerClient {\n    // raise the limit before serving\n    srv.MaxConnsPerIP = expectedConnsPerClient\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Size MaxConnsPerIP accounting for NAT/proxy aggregation.","Set clients to reuse keep-alive connections instead of opening many in parallel.","Load-test from multiple source IPs if per-IP limits are strict.","Monitor connection counts per IP to tune the limit."],"tags":["server","connection-limit","rate-limiting"],"backgroundTag":"per-ip-connection-limit-exceeded","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}