rqlite/rqlite · error

invalid capacity settings

Error message

invalid capacity settings

What it means

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.

Source

Thrown at tcp/pool/channel.go:32

	conns chan net.Conn

	// net.Conn generator
	factory    Factory
	nOpenConns int64
}

// Factory is a function to create new connections.
type Factory func() (net.Conn, error)

// NewChannelPool returns a new pool based on buffered channels with a maximum capacity.
// During a Get(), If there is no new connection available in the pool, a new connection
// will be created via the Factory() method.
func NewChannelPool(maxCap int, factory Factory) (Pool, error) {
	if factory == nil {
		return nil, errors.New("factory is nil")
	}
	if maxCap <= 0 {
		return nil, errors.New("invalid capacity settings")
	}
	return &channelPool{
		conns:   make(chan net.Conn, maxCap),
		factory: factory,
	}, nil
}

// Get implements the Pool interfaces Get() method. If there is no new
// connection available in the pool, a new connection will be created via the
// Factory() method. Do not call Get() on a closed pool.
func (c *channelPool) Get() (net.Conn, error) {
	conns, factory := c.getConnsAndFactory()
	if conns == nil {
		return nil, ErrClosed
	}

	// Wrap our connections with our custom net.Conn implementation (wrapConn
	// method) that puts the connection back to the pool if it's closed.

View on GitHub (pinned to 7586a4d1bd)

Solutions

  1. Pass a positive maxCap (e.g. default to a sane value like 5 when unset)
  2. Validate configured pool sizes at startup before constructing the pool
  3. Clamp or reject bad configuration with a clear message at load time

Example fix

// before
maxCap := cfg.PoolSize // could be 0
// after
maxCap := cfg.PoolSize
if maxCap <= 0 { maxCap = 5 } // default
pool, err := pool.NewChannelPool(maxCap, factory)
Defensive patterns

Strategy: validation

Validate before calling

if maxCap <= 0 {
  return errors.New("pool maxCap must be > 0")
}

Type guard

func validCapacity(n int) bool { return n > 0 }

Try / catch

p, err := pool.NewChannelPool(maxCap, factory)
if err != nil {
  return fmt.Errorf("pool init: %w", err)
}

Prevention

When it happens

Trigger: Calling NewChannelPool with maxCap <= 0, e.g. a config value of 0, an unset variable, or a negative default.

Common situations: Config-driven pool sizes where a YAML/env value is missing or zero; integer parsing failures silently producing 0.

Related errors


AI-assisted analysis of rqlite/rqlite@7586a4d1bd (2026-09-03). Data as JSON: /api/errors/53dcb386d7291f5f. Report an issue: GitHub.