process_resident_memory_bytes on your Traefik instance has been climbing for days. Request rates look normal, error rates are flat, and /ping returns 200. The question is whether the proxy legitimately needs more memory because its routing table grew, or whether it is leaking and will get OOM-killed at 3 a.m. with zero warning.
The failure mode is asymmetric. Go’s garbage collector absorbs growing allocation pressure gracefully, running more often and burning more CPU, until it cannot. Then the kernel OOM killer terminates the process instantly, dropping every connection in flight. There is no graceful degradation phase.
This guide separates the two cases: memory that tracks configuration size and traffic (expected), and memory that grows disconnected from both (a leak). The single most useful discriminator is the correlation between go_memstats_heap_inuse_bytes and go_goroutines.
What this means
Traefik’s memory footprint has three main drivers, each with a different trend signature:
Routing table size. Every router, middleware, and service in the dynamic configuration consumes heap. Traefik v2 and later use significantly more memory per route than v1 did, due to the middleware chain architecture. Large routing tables (10,000+ routes) can consume hundreds of MB at rest. If you migrated from v2 to v3 and memory jumped, or if your route count is growing, this is likely the explanation. See the hub page’s failure pattern catalogue for where “routing table explosion” sits among Traefik’s failure archetypes.
Connection and buffering state. One goroutine per active connection, plus middleware buffers. Middlewares that buffer request or response bodies (buffering, compression) consume memory proportional to body size times concurrent requests. Long-lived WebSocket and gRPC connections hold goroutines and buffers indefinitely.
Metric cardinality. Prometheus metrics with per-router labels (
addRoutersLabels: true) or high-cardinality header labels grow the in-memory metric store. Every unique label combination is a live series that is never freed.
A fourth category is genuine leaks: goroutines that never terminate (hung backend connections with no timeout), known middleware bugs, or plugin caches that never release. These show the same upward RSS trend but a different internal signature, which is what the diagnosis section isolates.
flowchart TD
A[RSS trending up over days] --> B{heap_inuse growing too?}
B -- No --> C[Go has not returned memory to OS.
Watch, but not a leak.]
B -- Yes --> D{Goroutines growing with it?}
D -- Yes --> E[Goroutine leak.
Capture pprof goroutine dump.]
D -- No --> F{Route count or reload rate growing?}
F -- Yes --> G[Legitimate routing-table growth.
Capacity-plan, consider providersThrottleDuration.]
F -- No --> H{Metric cardinality or middleware change?}
H -- Yes --> I[Cardinality growth or middleware leak.
Check labels, known issues.]
H -- No --> J[Capture heap profile with pprof.
Find the allocation site.]Common causes
| Cause | What it looks like | First thing to check |
|---|---|---|
| Routing table growth | heap_inuse tracks route count; goroutines stable; memory steps up on config reloads | Router/service count via /api/http/routers, config reload rate |
| v2 to v3 migration | Step change in baseline memory after upgrade, then stable | Route count unchanged but baseline higher; known v3 behavior |
| Goroutine leak | heap_inuse and go_goroutines rising together, disconnected from traffic | go_goroutines trend vs request rate; pprof goroutine dump |
| Compress middleware bug (v3.0-v3.2) | Rapid unbounded growth under load, sometimes tens of MB to GB | Traefik version; whether compress middleware is in use |
| Metric cardinality | Slow steady growth; correlates with number of distinct label values | addRoutersLabels, headerLabels config; metric series count |
| Body buffering middleware | Memory tracks traffic peaks, spiky, recovers partially | Whether buffering/compress middlewares are enabled |
| Regexp-heavy dynamic routes | Growth with route churn; regexp compiler allocations dominate heap profile | pprof heap profile showing regexp compilation |
| Long-lived connections | Goroutines and memory track WebSocket/gRPC connection count | traefik_open_connections trend vs request rate |
Quick checks
All read-only. Run them against the metrics endpoint and the process.
# Live heap vs mapped heap: heap_inuse is the number that matters
curl -s http://localhost:8080/metrics | grep -E 'go_memstats_heap_(inuse|sys|alloc)_bytes'
# Goroutine count: the leak discriminator
curl -s http://localhost:8080/metrics | grep go_goroutines
# Process RSS from the kernel's point of view
grep VmRSS /proc/$(pgrep traefik)/status
# Config churn: is the routing table being rebuilt constantly?
curl -s http://localhost:8080/metrics | grep traefik_config_reload
# Connection load: are connections accumulating?
curl -s http://localhost:8080/metrics | grep traefik_open_connections
Two interpretive rules before you go further:
- Use
heap_inuse, notheap_sys.go_memstats_heap_sys_bytesincludes memory the Go runtime has mapped from the OS but is not currently using. Go does not promptly return memory to the OS, soheap_sysand RSS can look alarming while live data is flat.go_memstats_heap_inuse_bytesis live allocations: if it is flat, you do not have a leak, you have a Go runtime holding onto freed pages. - Expect RSS to sit around 2x live data. With the default
GOGC=100, GC triggers when the heap doubles. Steady-state RSS of roughly twice the live heap is normal Go behavior, not a leak.
How to diagnose it
Establish the trend on heap_inuse, not RSS. Look at
go_memstats_heap_inuse_bytesover 24-72 hours. Flat with a sawtooth (GC cycles) is healthy. A rising floor after each GC cycle is growth. A monotonic climb is a leak until proven otherwise.Correlate with goroutines. Plot
go_goroutinesover the same window. If goroutines and heap_inuse rise together while request rate and open connections are flat, you have a goroutine leak: each leaked goroutine pins its stack and every heap object reachable from its closure. This is the most common true leak pattern in a Go proxy.Correlate with routing table size. If goroutines are stable, check whether configuration is growing. Pull the current router and service inventory:
# How many routers and services are actually loaded?
curl -s http://localhost:8080/api/http/routers | jq 'length'
curl -s http://localhost:8080/api/http/services | jq 'length'
Compare with historical values if you have them. Also check the traefik_config_reloads_total rate: frequent rebuilds in a churning environment allocate a new router/middleware/service object graph each time, and memory steps up with each rebuild if the table is growing. Rebuild CPU cost scales with routers times middlewares times services.
Check the version against known leaks. If you run Traefik v3.0 through v3.2 with the compress middleware enabled, you are exposed to a confirmed unbounded-growth bug in the compression algorithm priority, fixed in v3.3 (upstream issue #10859, fix PR #11641). Operators reported memory climbing from tens of MB to multiple GB under load with small route counts. If this matches your setup, upgrading or removing the compress middleware is the fix, not capacity planning. There are also upstream reports of regexp-heavy dynamic routing (issue #8044) and per-instance plugin caches (issue #11979) accumulating memory.
Check metric cardinality. If
addRoutersLabels: trueis set, every router adds label combinations to every metric. IfheaderLabelsmaps a high-cardinality header (User-Agent, request IDs) into metric labels, series count grows unboundedly and each series is resident memory. Note that theHostheader is promoted toRequest.Hostby Go and never appears in the header map, soheaderLabelson Host silently does nothing; useX-Forwarded-Hostif that is what you intended.Capture a heap profile. If none of the above explains it, get the allocation site directly. Enable
api.debug: truein the static configuration, then:
# Capture a heap profile (requires api.debug: true; served on the API/dashboard entrypoint)
go tool pprof http://localhost:8080/debug/pprof/heap
Look at what dominates inuse_space. TLS connection buffers (crypto/tls internals) point at long-lived connections. Regexp compilation internals point at route churn with regexp rules. Middleware buffers point at buffering under traffic. Enabling the debug API exposes pprof endpoints; bind them to a private interface and do not leave them reachable from untrusted networks.
Metrics and signals to monitor
| Signal | Why it matters | Warning sign |
|---|---|---|
go_memstats_heap_inuse_bytes | Live heap allocations; the real leak indicator | Rising floor after each GC cycle over days |
process_resident_memory_bytes | What the kernel and the OOM killer see | > 80% of container limit, sustained |
go_goroutines | Distinguishes goroutine leak from data growth | Rising with heap, disconnected from traffic |
go_gc_duration_seconds | GC struggling before the crash | p99 pause time climbing steadily week over week |
traefik_config_reloads_total rate | Config churn drives allocation and rebuild cost | > 1/second sustained |
| Router/service count (via API) | Direct measure of routing table size | Growth without a planned cause |
traefik_open_connections | Connection accumulation holds goroutines and buffers | Rising without corresponding request rate |
The degradation curve: GC pause latency climbs first, then OOM arrives with no further warning. If heap_inuse exceeds roughly 80% of the container memory limit, runway is minutes to seconds depending on allocation rate. Size container memory limits at about 2x the observed stable peak heap so the GC has headroom and traffic spikes are absorbable.
Fixes
Legitimate routing-table growth
If the routing table is genuinely that big, the fix is capacity and architecture, not debugging. Raise the container memory limit to 2x peak heap. Reduce rebuild pressure with providersThrottleDuration (default 2s in v2; batching provider events reduces both rebuild CPU and allocation churn). If a single instance’s routing table is pushing hundreds of MB and rebuilds are visible in latency, consider sharding: split route ownership across multiple Traefik instances by namespace, domain, or entrypoint.
Goroutine leak
Identify what the leaked goroutines are blocked on from a goroutine profile (/debug/pprof/goroutine?debug=1). The usual root cause is a backend that accepts TCP connections but never responds, combined with missing or overly long transport timeouts. Set dialTimeout, responseHeaderTimeout, and idleConnTimeout under serversTransport.forwardingTimeouts so stuck requests terminate. Remove the misbehaving backend from rotation while you fix it. Restarting Traefik clears the accumulated goroutines but does not fix the cause; treat it as buying runway only.
Compress middleware bug
Upgrade to v3.3 or later, where the compression algorithm priority was reverted to the v2 behavior. If you cannot upgrade immediately, removing the compress middleware stops the growth at the cost of uncompressed responses.
Metric cardinality
Turn off addRoutersLabels unless you genuinely need per-router metrics. Audit headerLabels and drop any label sourced from a high-cardinality header. If Prometheus itself is also growing, the cardinality explosion is on both sides and scraping will get slow before Traefik runs out of memory.
Connection accumulation
If traefik_open_connections grows without request-rate growth, connections are not being closed. Check keep-alive alignment between Traefik and any upstream load balancer (the classic mismatch: the upstream LB’s idle timeout is longer than Traefik’s, so the LB reuses connections Traefik already closed). WebSocket-heavy workloads need a separate baseline; long-lived connections holding goroutines and buffers is expected behavior, and the fix is capacity, not timeouts you do not want.
Prevention
- Alert on the pair, not the point. A static RSS threshold pages you too late or not at all. Alert on
heap_inusetrend over 24h and on heap/goroutine divergence from traffic baseline. Anomaly detection on the ratio of memory growth to request-rate growth catches leaks weeks before the OOM. - Baseline after every upgrade. v2-to-v3 changed the per-route memory cost. Re-baseline heap, goroutines, and rebuild rate after any version upgrade before you declare it clean.
- Cap config churn. Set
providersThrottleDurationdeliberately for your environment’s change rate, and investigate pathological provider churn (flapping health checks, autoscaler loops) rather than letting Traefik absorb it. - Set explicit transport timeouts. An unbounded
responseHeaderTimeoutis the single most common enabler of goroutine leaks. Every backend transport should have timeouts chosen deliberately. - Keep cardinality on a budget. Treat
addRoutersLabelsandheaderLabelsas spend decisions. If you enable per-router metrics, know your router count ceiling. - Watch GC pauses as the early warning. Rising
go_gc_duration_secondsp99 means the heap is outgrowing the collector, and it appears before latency degrades and well before OOM.
How Netdata helps
- Netdata charts
go_memstats_heap_inuse_bytesalongsideprocess_resident_memory_bytesper second, so you can see the post-GC floor rising (a leak) versus a flat floor under a high-water RSS (Go runtime behavior) without waiting for daily aggregates. - Overlaying
go_goroutineson the heap trend makes the core discriminator in this article a visual check: the two lines moving together, disconnected from request rate, is the leak signature. - Config reload rate and open connections sit on the same dashboard, so the “growing routing table” versus “growing connection state” branches of the decision tree are one screen apart.
go_gc_duration_secondspercentiles surface the GC-struggle phase of the degradation curve, giving you a warning stage before the OOM cliff.- ML-based anomaly detection on the memory-to-traffic relationship flags slow, multi-day drift that static thresholds on absolute RSS routinely miss.
Related guides
- Traefik 404 not found: requests arriving with no matching router
- Traefik 502 Bad Gateway: when the backend is unreachable or returns garbage
- Traefik 503 Service Unavailable: no healthy backends left in the pool
- Traefik 504 Gateway Timeout: the backend is alive but too slow
- Traefik 5xx error rate: telling Traefik-generated errors from backend errors
- Traefik ACME challenge failed: HTTP-01, DNS-01, and TLS-ALPN-01 renewal errors
- Traefik acme.json permissions and corruption: renewal silently blocked
- Traefik ACME rate limit: too many certificates already issued for this domain
- Traefik backend connection pool: keep-alive, MaxIdleConnsPerHost, and reuse
- Traefik cannot assign requested address: ephemeral port exhaustion
- Traefik cascading backend failure: how a partial outage becomes a total one
- Traefik certificate expired: when ACME renewal has been failing silently






