Skip to content

[bot-detection] Fix leak of background pre-warmer goroutine - #4589

Merged
buixor merged 3 commits into
masterfrom
fix_wasm_leak
Aug 3, 2026
Merged

[bot-detection] Fix leak of background pre-warmer goroutine#4589
buixor merged 3 commits into
masterfrom
fix_wasm_leak

Conversation

@buixor

@buixor buixor commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

reloads lead to a leak of dynamicModulePreWarmer (wasm runtime was shutdown, but not the associated go routine). Leads to increasing spam of this error in logs:

pre-warm of next epoch failed; first request after rotation will pay obfuscation cost

Copilot AI review requested due to automatic review settings August 3, 2026 12:51
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

@buixor: There are no 'kind' label on this PR. You need a 'kind' label to generate the release automatically.

  • /kind feature
  • /kind enhancement
  • /kind refactoring
  • /kind fix
  • /kind chore
  • /kind dependencies
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.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

@buixor: There are no area labels on this PR. You can add as many areas as you see fit.

  • /area agent
  • /area local-api
  • /area cscli
  • /area appsec
  • /area security
  • /area configuration
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Ready to approve

The change cleanly addresses the reported goroutine leak with minimal surface area and adds a targeted regression test to prevent recurrence.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR fixes a goroutine leak in the AppSec challenge runtime where dynamicModulePreWarmer could keep ticking after a reload closed the underlying wazero runtime, resulting in repeated warning logs and accumulating background goroutines.

Changes:

  • Run the dynamic-module pre-warmer under a Close()-owned cancellable context and cancel it during shutdown.
  • Suppress the expected “runtime closed” instantiation error during shutdown by exiting the pre-warmer when its context is canceled.
  • Add a regression test using go.uber.org/goleak to ensure the pre-warmer goroutine is not left behind after Close().
File summaries
File Description
pkg/appsec/challenge/dynamic_module.go Exits pre-warmer quietly on shutdown cancellation to avoid noisy warnings.
pkg/appsec/challenge/challenge.go Introduces preWarmCancel, wires a cancelable pre-warmer context, cancels it in Close().
pkg/appsec/challenge/close_test.go Adds goleak-based regression test ensuring Close() stops the pre-warmer goroutine.
go.mod Adds go.uber.org/goleak as a direct dependency for the new test.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.84%. Comparing base (380bb2e) to head (0ddd4e9).

Files with missing lines Patch % Lines
pkg/appsec/challenge/dynamic_module.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4589      +/-   ##
==========================================
- Coverage   64.36%   63.84%   -0.52%     
==========================================
  Files         499      516      +17     
  Lines       38544    39284     +740     
==========================================
+ Hits        24807    25079     +272     
- Misses      11413    11835     +422     
- Partials     2324     2370      +46     
Flag Coverage Δ
bats 41.65% <0.00%> (-0.01%) ⬇️
unit-linux 40.56% <71.42%> (-0.02%) ⬇️
unit-windows 29.26% <71.42%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@buixor

buixor commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/kind enhancement
/area appsec

@buixor
buixor merged commit 500a432 into master Aug 3, 2026
17 of 18 checks passed
@buixor
buixor deleted the fix_wasm_leak branch August 3, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/appsec kind/enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants