[GalaxyRepository] Per-filter projection cache is unbounded (1 GB from 2000 globs) #41
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
From the scadaproj#15 shared-library review (
code-reviews/GalaxyRepository/findings.md, GalaxyRepository-001), verified at91fb2b4. Update the finding's Resolution row when fixed.ZB.MOM.WW.GalaxyRepository/src/ZB.MOM.WW.GalaxyRepository/GalaxyHierarchyProjector.cs:28(memo insert:117); same pattern inZB.MOM.WW.GalaxyRepository/src/ZB.MOM.WW.GalaxyRepository/GalaxyBrowseProjector.cs:20(insert:121)Description
GalaxyHierarchyProjectorkeeps aConditionalWeakTable<GalaxyHierarchyCacheEntry, ConcurrentDictionary<string, IReadOnlyList<GalaxyObjectView>>>.Every distinct filter signature gets its own entry: root, max depth, category ids, template filters,
tag_name_glob, attribute/alarm/historized flags and browse globs. Each entry holds the full list ofmatching views, so a broad filter costs one reference per Galaxy object.
Nothing removes entries. The dictionary is released only when the cache publishes a new entry,
which happens only when
galaxy.time_of_last_deployadvances. In production that can be days orweeks apart.
GalaxyBrowseProjector.FilteredChildrenCachehas the same shape.tag_name_globis fully client-controlled.*,**,***and so on are all distinct signaturesthat match everything. The authors already treated client globs as hostile in
GalaxyGlobMatcher(its regex cache is deliberately capped at 256 for exactly this reason). The memo one layer up
received no such limit.
Failure scenario
Take a gateway (mxaccessgw or HistorianGateway) serving a 50k-object Galaxy. A client with a valid
API key, or a buggy client that builds a fresh glob per call, issues
DiscoverHierarchywith 2000distinct
tag_name_globvalues andpage_size=1.A scratch test of exactly this (
Project(entry, {TagNameGlob = new string('*', i)}, null, 0, 1)fori = 1..2000) retained 1010 MB. Memory keeps growing with every new glob until the next Galaxy
deploy. The gateway process (the x64 host that also brokers MXAccess or Historian traffic) can be
driven out of memory without a single SQL query.
Recommendation
Bound the memo per entry. Options:
page_tokenor is likely to page, i.e. whenTotalObjectCountexceeds the page size.Apply the same cap to
GalaxyBrowseProjector. Add a test that drives more than the cap of distinctglobs and asserts the memo size.
Resolution
Unresolved.
Fixed on main
20cf3bf(GalaxyRepository-001 → Resolved): both projectors use a new cache capped at 64 filter signatures, oldest out first; an evicted entry recomputes to the same answer (tested). GalaxyRepository 0.2.0 → 0.2.1, unpublished (with #42). Evidence: Overview 195/195, Theme 65/65, GalaxyRepository 74/74; each regression test failed before its fix; code-reviews --check consistent.