Bucket queues preallocate all their slots when the bucket is created
What happened?
pipeline.NewQueue allocates the whole queue (capacity, or cache_size when it is smaller) as soon as a bucket is created. A pipeline.Event is about 400 bytes, so a bucket with cache_size: 150 holds a 64 KiB array from its first event, however few events it gets.
On our host (agent and LAPI in one process, ~1000 sites behind nginx) a scenario grouped by ASN with cache_size: 150 keeps about 15.7k live buckets. The heap profile puts ~940 MiB of in-use memory on those 64 KiB pipeline.NewQueue allocations. The crowdsec process RSS is 7.9 GB.
What did you expect to happen?
Queue memory follows the events a bucket actually holds.
How can we reproduce it?
Run a leaky scenario with a large capacity or cache_size and a groupby that creates many buckets with few events each, then check go tool pprof -sample_index=inuse_space http://127.0.0.1:6060/debug/pprof/heap: pipeline.NewQueue holds cap * sizeof(Event) per live bucket.
Anything else we need to know?
Creating the slice empty is enough: Queue.Add already trims to L before appending. Buckets that fill up end with the same array size as now, since the current code also reallocates on the L+1-th event. Fix with a test: https://github.com/AdzerKI/crowdsec/commit/55da8fe3
Crowdsec version
$ cscli version
version: v1.8.2-debian-pragmatic-amd64-3d369d64
Codename: alphaga
BuildDate: 2026-10-27_14:05:00
GoVersion: 1.27.1
Platform: linux
pkg/pipeline/queue.go is the same on master.
OS version
Ubuntu 24.04
@AdzerKI: Thanks for opening an issue, it is currently awaiting triage.
In the meantime, you can:
- Check Crowdsec Documentation to see if your issue can be self resolved.
- You can also join our Discord.
- Check Releases to make sure your agent is on the latest version.
Details
I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.
@AdzerKI: There are no 'kind' label on this issue. You need a 'kind' label to start the triage process.
/kind feature/kind enhancement/kind refactoring/kind bug/kind packaging
Details
I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.
/kind bug