t8y2/dbx · error
Not connected. Call connect first.
Error message
Not connected. Call connect first.
What it means
channelFor first tries the primary/default-vhost channel; for a non-default vhost it needs a cached connection established by connect(). If no cached connection exists it cannot open a vhost client and throws this error telling you to connect first.
Source
Thrown at agents/drivers/rabbitmq/main.go:426
amqpConfig.TLSClientConfig = &tls.Config{
ServerName: endpoint.Host,
InsecureSkipVerify: tlsSkipVerify(config),
}
}
return amqp.DialConfig(uri.String(), amqpConfig)
}
func (s *server) channelFor(params jsonObject) (*amqp.Channel, error) {
defaultVhost := "/"
if s.cachedConnection != nil {
defaultVhost = stringOrDefault(s.cachedConnection, "virtual_host", "/")
}
vhost := effectiveVhost(params, s.cachedConnection)
if vhost == defaultVhost {
return s.primaryChannel()
}
if s.cachedConnection == nil {
return nil, errors.New("Not connected. Call connect first.")
}
if client := s.vhostClients[vhost]; client != nil && client.isOpen() {
return client.channel, nil
} else if client != nil {
client.close()
delete(s.vhostClients, vhost)
}
config := deepCopyObject(s.cachedConnection)
config["virtual_host"] = vhost
connection, err := openConnection(config)
if err != nil {
return nil, err
}
channel, err := connection.Channel()
if err != nil {
closeConnection(connection)
return nil, err
}View on GitHub (pinned to c0390bff16)
Solutions
- Call mq_connect before performing vhost-scoped operations
- Check/propagate the error from connect instead of ignoring it
- Or pass the default vhost (omit virtual_host) so primaryChannel is used
Example fix
// before
agent.Call("mq_purge_queue", map[string]any{"topic": "q", "virtual_host": "staging"})
// after
agent.Call("mq_connect", map[string]any{"addresses": "rabbit:5672"})
agent.Call("mq_purge_queue", map[string]any{"topic": "q", "virtual_host": "staging"}) Defensive patterns
Strategy: try-catch
Try / catch
_, err := agent.Call("mq_purge_queue", params)
if err != nil && strings.Contains(err.Error(), "Not connected") {
if _, cerr := agent.Call("mq_connect", connectCfg); cerr != nil { return cerr }
_, err = agent.Call("mq_purge_queue", params) // retry once after connect
} Prevention
- Always call mq_connect before queue operations, including vhost-scoped ones
- Handle connect errors instead of ignoring them
- Wrap operations with an ensureConnected helper
When it happens
Trigger: Calling createTopic/deleteTopic/getTopicStats/getTopicConfig/purgeQueue/applyBinding with a virtual_host other than the default before mq_connect was ever called (or after its cached connection was cleared).
Common situations: Using an agent instance fresh from construction for vhost-scoped ops; a previous connect failed silently and was ignored; long-lived process where cached state was reset but ops continue.
Related errors
- Kafka Agent is not connected
- Not connected
- ZooKeeper event stream closed before a session was establish
- Not connected
- ZooKeeper event stream closed before a session was establish
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/4867388f53e3221a.
Report an issue: GitHub.