{"record":{"id":"53dcb386d7291f5f","repo":"rqlite/rqlite","slug":"invalid-capacity-settings","errorCode":null,"errorMessage":"invalid capacity settings","messagePattern":"invalid capacity settings","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tcp/pool/channel.go","lineNumber":32,"sourceCode":"\tconns chan net.Conn\n\n\t// net.Conn generator\n\tfactory    Factory\n\tnOpenConns int64\n}\n\n// Factory is a function to create new connections.\ntype Factory func() (net.Conn, error)\n\n// NewChannelPool returns a new pool based on buffered channels with a maximum capacity.\n// During a Get(), If there is no new connection available in the pool, a new connection\n// will be created via the Factory() method.\nfunc NewChannelPool(maxCap int, factory Factory) (Pool, error) {\n\tif factory == nil {\n\t\treturn nil, errors.New(\"factory is nil\")\n\t}\n\tif maxCap <= 0 {\n\t\treturn nil, errors.New(\"invalid capacity settings\")\n\t}\n\treturn &channelPool{\n\t\tconns:   make(chan net.Conn, maxCap),\n\t\tfactory: factory,\n\t}, nil\n}\n\n// Get implements the Pool interfaces Get() method. If there is no new\n// connection available in the pool, a new connection will be created via the\n// Factory() method. Do not call Get() on a closed pool.\nfunc (c *channelPool) Get() (net.Conn, error) {\n\tconns, factory := c.getConnsAndFactory()\n\tif conns == nil {\n\t\treturn nil, ErrClosed\n\t}\n\n\t// Wrap our connections with our custom net.Conn implementation (wrapConn\n\t// method) that puts the connection back to the pool if it's closed.","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/rqlite/rqlite/blob/7586a4d1bdbd9a5a80021664c5a863cd850adb60/tcp/pool/channel.go#L14-L50","documentation":"NewChannelPool validates that maxCap is greater than zero; a non-positive capacity would create a useless (or zero-capacity, always-blocking) buffered channel. The pool refuses construction with this error.","triggerScenarios":"Calling NewChannelPool with maxCap <= 0, e.g. a config value of 0, an unset variable, or a negative default.","commonSituations":"Config-driven pool sizes where a YAML/env value is missing or zero; integer parsing failures silently producing 0.","solutions":["Pass a positive maxCap (e.g. default to a sane value like 5 when unset)","Validate configured pool sizes at startup before constructing the pool","Clamp or reject bad configuration with a clear message at load time"],"exampleFix":"// before\nmaxCap := cfg.PoolSize // could be 0\n// after\nmaxCap := cfg.PoolSize\nif maxCap <= 0 { maxCap = 5 } // default\npool, err := pool.NewChannelPool(maxCap, factory)","handlingStrategy":"validation","validationCode":"if maxCap <= 0 {\n  return errors.New(\"pool maxCap must be > 0\")\n}","typeGuard":"func validCapacity(n int) bool { return n > 0 }","tryCatchPattern":"p, err := pool.NewChannelPool(maxCap, factory)\nif err != nil {\n  return fmt.Errorf(\"pool init: %w\", err)\n}","preventionTips":["Default pool size when config value is 0/unset","Validate parsed config at startup","Never pass unchecked env/config integers as capacity"],"tags":["golang","tcp","connection-pool","validation"],"backgroundTag":"invalid-configuration","analyzedSha":"7586a4d1bdbd9a5a80021664c5a863cd850adb60","analyzedAt":"2026-09-03T07:03:02.260Z","contentChangedAt":"2026-09-03T07:03:02.260Z","schemaVersion":2},"datasetVersion":"2026-09-10T12:17:11.382Z"}