rqlite/rqlite · warning

connection is nil. rejecting

Error message

connection is nil. rejecting

What it means

Generic defensive guard in the TCP connection pool's put(): it rejects returning a nil net.Conn to the pool instead of panicking later on a nil dereference. Fires only from a caller bug — putting a nil connection that was never established or was already consumed.

Source

Thrown at tcp/pool/channel.go:122

	conns, _ := c.getConnsAndFactory()
	return len(conns)
}

// Stats returns stats for the pool.
func (c *channelPool) Stats() (map[string]any, error) {
	conns, _ := c.getConnsAndFactory()
	return map[string]any{
		"idle":                 len(conns),
		"open_connections":     c.nOpenConns,
		"max_open_connections": cap(conns),
	}, nil
}

// put puts the connection back to the pool. If the pool is full or closed,
// conn is simply closed. A nil conn will be rejected.
func (c *channelPool) put(conn net.Conn) error {
	if conn == nil {
		return errors.New("connection is nil. rejecting")
	}
	c.mu.Lock()
	defer c.mu.Unlock()

	if c.conns == nil {
		// pool is closed, close passed connection
		atomic.AddInt64(&c.nOpenConns, -1)
		return conn.Close()
	}

	// put the resource back into the pool. If the pool is full, this will
	// block and the default case will be executed.
	select {
	case c.conns <- conn:
		return nil
	default:
		// pool is full, close passed connection
		atomic.AddInt64(&c.nOpenConns, -1)

View on GitHub (pinned to 7586a4d1bd)

Solutions

  1. Ensure only non-nil connections obtained via Get() are put back
  2. Guard call sites: skip put when the connection is nil
  3. On pool Close, close conns directly instead of routing through put

Example fix

// before
p.put(conn) // conn may be nil
// after
if conn != nil {
  p.put(conn)
}
Defensive patterns

Strategy: validation

Validate before calling

if conn == nil {
  return errors.New("cannot put nil connection into pool")
}

Type guard

func putIfNotNil(p *pool.ChannelPool, c net.Conn) {
  if c != nil { p.Put(c) }
}

Try / catch

if err := p.Put(conn); err != nil {
  log.Printf("put rejected: %v", err)
}

Prevention

When it happens

Trigger: Calling put(conn) with a nil net.Conn, typically from Close() when iterating pooled connections, or from code paths that retrieve nothing but still call put.

Common situations: Pool teardown code that calls put on already-closed/zero-value connections; bugs in wrapper code that lost the real connection.

Related errors


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