micro/go-micro · warning
channel is nil
Error message
channel is nil
What it means
rabbitMQChannel.Close() checks that the underlying AMQP channel pointer is non-nil before delegating to channel.Close(). If the channel was never created (no successful connect/open) or was already torn down, Close returns "channel is nil" instead of panicking on a nil pointer.
Source
Thrown at broker/rabbitmq/channel.go:64
if err != nil {
return err
}
if confirmPublish {
r.confirmPublish = r.channel.NotifyPublish(make(chan amqp.Confirmation, 1))
err = r.channel.Confirm(false)
if err != nil {
return err
}
}
return nil
}
func (r *rabbitMQChannel) Close() error {
if r.channel == nil {
return errors.New("channel is nil")
}
return r.channel.Close()
}
func (r *rabbitMQChannel) Publish(exchange, key string, message amqp.Publishing) error {
if r.channel == nil {
return errors.New("channel is nil")
}
if r.confirmPublish != nil {
r.mtx.Lock()
defer r.mtx.Unlock()
}
err := r.channel.Publish(exchange, key, false, false, message)
if err != nil {
return err
}View on GitHub (pinned to 24529f1404)
Solutions
- Skip treating this as fatal on shutdown — the resource is already gone; log and continue.
- Track channel state in your code and only call Close once.
- Reconnect the broker (broker.Connect) before creating new channels if the connection dropped.
Example fix
// before
ch.Close() // panics-ish: "channel is nil"
// after
if err := ch.Close(); err != nil && err.Error() != "channel is nil" {
log.Printf("close failed: %v", err)
} Defensive patterns
Strategy: validation
Validate before calling
// only Close a channel you successfully opened and haven't closed
if !channelOpened { skipClose() } Try / catch
if err := ch.Close(); err != nil && err.Error() != "channel is nil" {
log.Printf("channel close failed: %v", err)
} Prevention
- Call Close exactly once per channel using sync.Once or a closed flag.
- Don't Close channels after a failed Connect.
- Treat 'channel is nil' during shutdown as already-cleaned-up, not fatal.
When it happens
Trigger: Calling Close() on a rabbitMQChannel whose underlying *amqp.Channel is nil — channel never opened, or closed/recycled elsewhere first.
Common situations: Deferred cleanup after a failed Connect; double-Close in shutdown handlers; using a channel after the RabbitMQ connection dropped and the channel was discarded.
Related errors
- channel closed before could receive confirmation of publish
- could not publish message, received nack from broker on conf
- connection is nil
- not connected
- agent: checkpointed run is terminal with status
AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01).
Data as JSON: /api/errors/def34d44357b2332.
Report an issue: GitHub.