{"record":{"id":"077381ddba1da700","repo":"micro/go-micro","slug":"errpoolexhausted","errorCode":"ErrPoolExhausted","errorMessage":"connection pool exhausted","messagePattern":"connection pool exhausted","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"broker/nats/pool.go","lineNumber":13,"sourceCode":"package nats\n\nimport (\n\t\"errors\"\n\t\"sync\"\n\t\"time\"\n\n\tnatsp \"github.com/nats-io/nats.go\"\n)\n\nvar (\n\t// ErrPoolExhausted is returned when no connections are available in the pool\n\tErrPoolExhausted = errors.New(\"connection pool exhausted\")\n\t// ErrPoolClosed is returned when trying to use a closed pool\n\tErrPoolClosed = errors.New(\"connection pool is closed\")\n)\n\n// connectionPool manages a pool of NATS connections\ntype connectionPool struct {\n\tmu          sync.RWMutex\n\tconnections chan *pooledConnection\n\tfactory     func() (*natsp.Conn, error)\n\tsize        int\n\tidleTimeout time.Duration\n\tclosed      bool\n}\n\n// pooledConnection wraps a NATS connection with metadata\ntype pooledConnection struct {\n\tconn      *natsp.Conn\n\tcreatedAt time.Time","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/broker/nats/pool.go#L1-L31","documentation":"ErrPoolExhausted is a sentinel error returned by the NATS connectionPool's Get when every connection in the pool is checked out and none are available. The pool is bounded (a fixed-size channel of connections), so concurrent demand above the pool size yields this error instead of blocking indefinitely.","triggerScenarios":"Calling pool.Get() (via Subscribe) when the connections channel is empty — more concurrent operations than pool capacity, or connections leaked (never Put back after a panic or early return).","commonSituations":"High-concurrency subscribers exceeding the configured pool size; leaked connections from error paths that skip releasing; benchmarks/load tests with many goroutines sharing one broker instance.","solutions":["Increase the pool size in the broker configuration to match peak concurrency.","Ensure every code path that Get()s a connection returns it with pool.Put(), including error paths.","Retry with backoff — connections are returned as concurrent operations complete."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if err == natsbroker.ErrPoolExhausted {\n    // increase pool size or retry with backoff\n}","typeGuard":null,"tryCatchPattern":"sub, err := b.Subscribe(topic, handler)\nif errors.Is(err, natsbroker.ErrPoolExhausted) {\n    time.Sleep(backoff)\n    sub, err = b.Subscribe(topic, handler)\n}","preventionTips":["Size the pool at or above peak concurrent subscriber operations.","Always release pooled connections on every code path (defer pool.Put).","Watch for error repeats under load as a signal to raise pool capacity."],"tags":["nats","connection-pool","resource-exhaustion","sentinel-error"],"backgroundTag":"connection-pool-exhausted","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}