Bot Detection Signing Key Rotation triggers synchronous WASM reload causing CPU spikes every 5 minutes

Open
#4,795 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
go, wasm
Domain
backend, security

Research direction

Start by tracing the AppSec engine’s Bot Detection signing-key rotation timer and the synchronous WASM reload it triggers; the issue does not name specific files or tests. Confirm the reload’s timing and CPU impact, then determine which proposed direction fits the project. Done means rotation no longer causes the reported recurring CPU spike while preserving key rotation behavior.

Written by the indexing model from the issue text.

Description

needs/kind needs/triage

Description

When CrowdSec AppSec Bot Detection is enabled, the Signing Key Rotation mechanism triggers a synchronous WASM module reload every 5 minutes (default rotation_interval=5m0s). This causes a predictable CPU spike lasting 4-5 seconds on small-instance deployments, during which the WASM runtime consumes 100% of a single core. On 2-core machines under concurrent load, this can cause request latency degradation or brief service unavailability.

The CPU spike is traffic-independent — it occurs at fixed intervals regardless of request volume, confirming it is an internal timer-driven operation rather than a response to incoming traffic.

Cause Analysis

The CPU spike is caused by the Bot Detection Signing Key Rotation timer (rotation_interval=5m0s), which triggers a synchronous WASM module reload in the AppSec engine. Key evidence:

  1. Spike timing aligns exactly with rotation_interval (not with traffic patterns or cron jobs)
  2. CrowdSec log shows: WAF challenge runtime initialized ... rotation_interval=5m0s
  3. Memory profile shows full WASM module deallocation + reallocation cycle
  4. The operation is single-threaded and blocks the AppSec runner during reload
  5. Multiple signing keys would make this WORSE (more frequent reloads), not better

Suggested Improvements

  1. Async WASM hot-reload: Perform signing key rotation and WASM module swap in a background goroutine, swapping the active module atomically after preparation completes
  2. Configurable rotation interval: Allow users to tune rotation_interval based on their security/performance tradeoff (e.g., 15m or 30m for small instances)
  3. Lazy rotation: Only rotate when the current key has been used for N challenges, rather than on a fixed timer
  4. WASM module pooling: Pre-allocate the new WASM instance before tearing down the old one to reduce memory allocation pressure
Dominant language
Go
Stars
15.1k
Forks
726
Avg merge
4d 23h
Merged PRs (30d)
27

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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 crowdsecurity/crowdsec

All issues in crowdsecurity/crowdsec

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.