Memory leak using Caddy Souin cache + Badger #890

Open
#2,357 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
go
Domain
databases

Research direction

The report names Badger’s skl.newArena and Ristretto’s z.Calloc in Go heap profiles, but gives no reproduction steps or Badger-specific configuration beyond the Caddy cache setup. Start by identifying whether either allocation grows under a reproducible workload and checking the relevant Badger allocation paths. Done means a reproducible cause and fix or guidance that establishes the growth is expected.

Written by the indexing model from the issue text.

Description

Describe the bug

Not sure where's best to report this apparent memory leak. Using Caddy cache module with badger storage, writing to disk under /var/cache rather than in-memory. Is there other useful info I can share?

Go heap profiling yesterday:

      flat  flat%   sum%        cum   cum%
  332.80MB 87.02% 87.02%   332.80MB 87.02%  github.com/dgraph-io/badger/v4/skl.newArena
   22.55MB  5.90% 92.91%    22.55MB  5.90%  github.com/dgraph-io/badger/v4/y.SafeCopy
    6.52MB  1.70% 94.62%     6.52MB  1.70%  github.com/dgraph-io/ristretto/v2/z.Calloc

Go heap profiling today:

      flat  flat%   sum%        cum   cum%
  332.80MB 53.37% 53.37%   332.80MB 53.37%  github.com/dgraph-io/badger/v4/skl.newArena
  258.34MB 41.43% 94.80%   258.34MB 41.43%  github.com/dgraph-io/ristretto/v2/z.Calloc (inline)
       8MB  1.28% 96.08%        8MB  1.28%  github.com/pierrec/lz4/v4/internal/lz4block.init.func6
    7.12MB  1.14% 97.22%     7.12MB  1.14%  bytes.growSlice
    0.85MB  0.14% 97.36%     4.49MB  0.72%  github.com/darkweak/souin/pkg/surrogate/providers.(*baseStorage).storeTag
         0     0% 97.36%     3.26MB  0.52%  bytes.(*Buffer).Grow
         0     0% 97.36%     7.12MB  1.14%  bytes.(*Buffer).grow
         0     0% 97.36%    39.98MB  6.41%  github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP
         0     0% 97.36%    39.98MB  6.41%  github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).enforcementHandler
         0     0% 97.36%    39.98MB  6.41%  github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).serveHTTP

Caddy profiing:

Count Profile
7092 allocs
0 block
0 cmdline
77* goroutine
0 goroutineleak
7092** heap
0 mutex
0 profile
0 symbol
7 threadcreate
0 trace

/* goes up and down
/** increases pretty constantly

To Reproduce

Unclear. My badger configuration in Caddyfile is as follows:

	cache {
		timeout {
			backend 60s
			cache 2s
		}
		allowed_http_verbs GET
		key {
			hash
			disable_query
		}
		ttl 1h
		default_cache_control max-age=3600
		badger {
			path /var/cache/badger/site_cache
		}
        }

Expected behavior

Normal memory usage, without heap count constantly increasing.

Screenshots

If applicable, add screenshots to help explain your problem.

Environment

  • OS: Linux
  • Language Go

Additional context

Add any other context about the problem here.

Dominant language
Go
Stars
15.8k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dgraph-io/badger

All issues in dgraph-io/badger

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.