Skip to content

BUG: Metric collector goroutine leak on non-EOF Prometheus decode errors #1329

Description

@kunal-yelgate

What happened:

While reviewing the metrics collection logic in the autoscaler, I found that the Prometheus metrics decoding loop in pkg/controller/autoscaler/metric_collector.go only exits on io.EOF. However, non-EOF errors (e.g., network timeouts, malformed responses, connection resets) cause the loop to spin indefinitely with continue, leading to:

  1. Goroutine leaks — the collector goroutine never terminates
  2. CPU spin — tight loop on persistent decode errors
  3. Autoscaler crash — under sustained load with flaky metrics endpoints

This pattern was partially addressed in related reliability work (see PR #952), but the metric collector's decode loop lacks proper error handling and backoff.

The problematic code:

for {
    var metric prom2json.Family
    if err := decoder.Decode(&metric); err != nil {
        if err == io.EOF {
            break
        }
        // BUG: continues looping on non-EOF errors without backoff
        continue  
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions