Bound the in-memory report registry to avoid unbounded growth - #82
Open
arpitjain099 wants to merge 1 commit into
Open
Bound the in-memory report registry to avoid unbounded growth#82arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
The completed-report registry (_report_registry) stored a full Analyzer, including its parsed-pcap pandas frames, on every analysis and was never evicted or capped. Its companion dict _progress_queues is popped in the WebSocket cleanup path, but the heavier report registry kept growing for the lifetime of the worker, so repeated analyses steadily increased memory. Back the registry with an OrderedDict capped at MAX_STORED_REPORTS and evict the oldest entry once the cap is reached. Reads through _require_analyzer move the entry to the end so an actively used report is not the first evicted, which keeps the drilldown routes working for recent reports. Add tests covering the size bound and the least-recently-used eviction order. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi, I do supply-chain-security work and was reading through the eleVADR backend. I noticed the completed-report registry can grow without bound, so here is a small hardening fix.
In
backend/src/app/main.py,_report_registrystores the fullAnalyzerfor each analysis, and each Analyzer holds the parsed-pcap pandas frames (traffic_df,endpoints_df,services_df). The only writes are the insert inrun_analysisand the read in_require_analyzer; nothing ever evicts or caps it. Its sibling dict_progress_queuesdoes get cleaned up (the WebSocketfinallyblock pops it), but the heavier report registry keeps every entry for the lifetime of the worker, so memory climbs steadily as more PCAPs are analyzed.The change backs the registry with an
OrderedDictcapped atMAX_STORED_REPORTS(32) and evicts the oldest entry once the cap is reached. Reads through_require_analyzermove the entry to the end, so a report that is actively being drilled into is not the first one evicted. The existing drilldown read path keeps working for recent reports, which is the common case.Tests: I added two cases in
backend/tests/test_main.pycovering the size cap and the least-recently-used eviction order. Both pass under Python 3.14, and I confirmed they fail against the previous unbounded behavior. The fulltest_main.pysuite (14 tests) stays green and ruff is clean on the edited source.If you would rather I raise the 32 default differently, or handle eviction some other way (a TTL or an explicit delete on drilldown completion were alternatives I considered), happy to adjust. Thanks for the tool.