fix(router): consolidated config-reload memory-leak fix (#3006–#3009 bundle)#3020
fix(router): consolidated config-reload memory-leak fix (#3006–#3009 bundle)#3020asoorm wants to merge 4 commits into
Conversation
… values After Close(), cached entries in the sync.Map could keep references to stored values (including query plans holding schema AST pointers) until the Cache struct itself was collected. Clear entries when shutting down the cache so config reload can release the previous graph generation.
planWithMetaData stored schemaDocument (full router schema AST, ~200MB) in every cached plan entry but never read it. Drop the field so plan caches do not retain the old schema generation after config reload.
The supervisor restart path already extracts slow-plan cache entries before replacing the graph server. Call the same hook at the start of newServer() so CDN and manifest hot-reloads release stale plan cache references while the old graphMux is still alive.
Ristretto Close() clears all plan cache entries and fires OnEvict for each one, migrating them into slowplancache right before both caches are torn down. Disable OnEvict during intentional mux shutdown and wait for pending slow-cache writes first.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
WalkthroughThe router updates internal plan metadata, reload timing, eviction handling during shutdown, and slow plan cache teardown. A new test covers the cache close behavior. ChangesPlan cache lifecycle updates
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Comment |
Router image scan passed✅ No security vulnerabilities found in image: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3020 +/- ##
==========================================
- Coverage 60.27% 51.03% -9.25%
==========================================
Files 477 243 -234
Lines 62471 29475 -32996
Branches 6131 0 -6131
==========================================
- Hits 37656 15042 -22614
+ Misses 24787 12903 -11884
- Partials 28 1530 +1502
🚀 New features to boost your workflow:
|
What
Consolidated bundle of the four root-cause fixes for memory retention on router config hot-reload, combined onto one branch so the leak can be validated end-to-end in a single checkout.
Commits (cherry-picked, in merge order)
Root cause
On reload,
graphMux.Shutdown()→planCache.Close()triggers ristretto'sClear(), which fires the plan cacheOnEvictfor every entry, demoting the whole cache intoplanFallbackCache. That fallback is held by the long-livedreloadPersistentState(core/graph_server.go:1609), andslowplancache.Close()didn't clear its map — so the old plan cache + schema AST survived every reload. The fix set stops the demote-on-shutdown, clears the fallback on close, releases stale refs in the hot-reload path, and drops the unused schema-AST field.Validation
go build ./...).TestReloadConfig_PlanCacheRetentionLeak) is red onmainand green on this branch.Why draft
Coordination/validation branch for #3006–#3009 — not intended to merge on its own.
Summary by CodeRabbit
Bug Fixes
Tests