fix: limit memory leak to AppSec being enabled#7276
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7276 +/- ##
=======================================
Coverage 80.34% 80.35%
=======================================
Files 731 731
Lines 31093 31105 +12
=======================================
+ Hits 24981 24993 +12
Misses 6112 6112
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Overall package sizeSelf size: 4.58 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.6 | 81.92 kB | 813.08 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
This comment has been minimized.
This comment has been minimized.
This fixes a memory leak by making sure the exposed req and res of http are not hold onto strongly. It does that by skipping adding these to the store, if not needed as well as creating a WeakRef when it is needed. That way AppSec still has access to these as long as the request is alive. Router now also uses a WeakMap for the context to prevent any hard references and the parent store in http server is refactored next to using private properties and adding some types. Fixes: #6389
ac69075 to
8ae52ce
Compare
BenchmarksBenchmark execution time: 2026-02-09 00:53:19 Comparing candidate commit 8614498 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 231 metrics, 29 unstable metrics. |
| class RouterPlugin extends WebPlugin { | ||
| static id = 'router' | ||
|
|
||
| #storeStacks = new WeakMap() |
There was a problem hiding this comment.
These changes are a nice to have, but unrelated to this PR and in the future it would be best to make those unrelated changes in another PR to avoid unnecessary noise.
This fixes a memory leak by making sure the exposed req and res ofhttp are not hold onto strongly.
It does that by skipping adding these to the store, if not needed
as well as creating a WeakRef when it is needed. That way AppSec
still has access to these as long as the request is alive.
This limits a AppSec specific memory leak to only surface in case AppSec
is enabled. That is just a stop gap to limit the impact on our users until we
have a proper fix that needs further rework.
Refs: #6389
Router now correlates the storeStacks to the correct middleware exit.
Before, these were expected to always be in order while multiple parallel
calls could potentially interfere with that and correlate wrong entries.