hibiken/asynq · error
failed to get queue names
Error message
failed to get queue names: %w
What it means
QueueMetricsCollector.collectQueueInfo calls Inspector.Queues() to list all queue names and wraps any underlying Redis/transport error with this message. Collect propagates it, failing the whole Prometheus scrape for this collector since queue info cannot be gathered.
Solutions
- Check Redis connectivity from the exporter (redis-cli ping) and fix REDIS address/credentials.
- Unwrap the %w-wrapped cause to identify the underlying error (connection refused, auth, timeout).
- Make the Inspector's RedisConnOpt point to the correct, reachable Redis instance.
- Add retry/backoff in the collector or handle per-scrape errors in Prometheus instrumentation.
Example fix
// before
inspector := asynq.NewInspector(asynq.RedisClientOpt{Addr: ""})
// after
inspector := asynq.NewInspector(asynq.RedisClientOpt{Addr: "localhost:6379", Password: os.Getenv("REDIS_PASSWORD")})
if _, err := inspector.Queues(); err != nil {
log.Fatalf("redis unreachable: %v", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
insp := asynq.NewInspector(redisOpt)
if _, err := insp.Queues(); err != nil {
log.Fatalf("redis unreachable for metrics: %v", err)
} Try / catch
if infos, err := qmc.collectQueueInfo(); err != nil {
log.Printf("metrics collection failed: %v", err) // keep scrape alive
return prometheus.NoopCollector
} Prevention
- Health-check Redis connectivity before registering the metrics collector.
- Use connection retry/timeouts in RedisClientOpt.
- Alert on Redis reachability separately so scrapes failing is a symptom, not the first signal.
- Verify exporter REDIS address/password match the asynq server's.
When it happens
Trigger: Prometheus scrape invokes Collect → collectQueueInfo; Inspector.Ques()/Queues() fails due to Redis connection failure, auth failure, closed connection, or the underlying client not initialized.
Common situations: Redis down or restarted when Prometheus scrapes; wrong REDIS address/password in the metrics exporter config; network partition between exporter and Redis; using an Inspector built with invalid RedisConnOpt.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- failed to get queue info
- redis connection is shared so the Inspector can't be closed…
- redis command failed
- task id conflicts with another task
- testutil: redis is down
AI-assisted analysis of hibiken/asynq@d135f1439b (2026-09-07).
Data as JSON: /api/errors/816e22808baf6ce4.
Report an issue: GitHub.
Appendix: source
Thrown at x/metrics/metrics.go:28
)
// Namespace used in fully-qualified metrics names.
const namespace = "asynq"
// QueueMetricsCollector gathers queue metrics.
// It implements prometheus.Collector interface.
//
// All metrics exported from this collector have prefix "asynq".
type QueueMetricsCollector struct {
inspector *asynq.Inspector
}
// collectQueueInfo gathers QueueInfo of all queues.
// Since this operation is expensive, it must be called once per collection.
func (qmc *QueueMetricsCollector) collectQueueInfo() ([]*asynq.QueueInfo, error) {
qnames, err := qmc.inspector.Queues()
if err != nil {
return nil, fmt.Errorf("failed to get queue names: %w", err)
}
infos := make([]*asynq.QueueInfo, len(qnames))
for i, qname := range qnames {
qinfo, err := qmc.inspector.GetQueueInfo(qname)
if err != nil {
return nil, fmt.Errorf("failed to get queue info: %w", err)
}
infos[i] = qinfo
}
return infos, nil
}
// Descriptors used by QueueMetricsCollector
var (
tasksQueuedDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "tasks_enqueued_total"),
"Number of tasks enqueued; broken down by queue and state.",
[]string{"queue", "state"}, nil,View on GitHub (pinned to d135f1439b)