Skip to content

fix(router): clear slowplancache entries on Close#3006

Closed
arutkowski00 wants to merge 2 commits into
wundergraph:mainfrom
mondaycom:adamru/upstream-bugfix-slowplancache-clear
Closed

fix(router): clear slowplancache entries on Close#3006
arutkowski00 wants to merge 2 commits into
wundergraph:mainfrom
mondaycom:adamru/upstream-bugfix-slowplancache-clear

Conversation

@arutkowski00

@arutkowski00 arutkowski00 commented Jun 24, 2026

Copy link
Copy Markdown

Problem

After slowplancache.Close(), entries remained in the underlying sync.Map, keeping references to cached query plans (and any schema pointers they hold) until the Cache struct was garbage-collected.

Fix

Clear all entries and reset the size counter when Close() runs.

Test plan

  • TestCache_CloseReleasesEntries
  • go test ./router/pkg/slowplancache/...

Part of config hot-reload memory leak investigation (monday.com #3221).

Summary by CodeRabbit

  • Bug Fixes

    • Improved cache shutdown so stored entries are fully cleared when the cache is closed.
    • Ensured cached data is released immediately, with internal cache size reset to zero.
  • Tests

    • Added coverage to verify that closing the cache removes all stored entries and leaves no retained size.

… 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.
@arutkowski00 arutkowski00 requested a review from a team as a code owner June 24, 2026 21:13
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cdd8b1ac-0a76-4405-b96f-3f507152304c

📥 Commits

Reviewing files that changed from the base of the PR and between 79155f1 and 6b68dae.

📒 Files selected for processing (2)
  • router/pkg/slowplancache/slow_plan_cache.go
  • router/pkg/slowplancache/slow_plan_cache_test.go

Walkthrough

Cache.Close() now clears stored entries after shutting down the writer and resets the tracked size. A new unit test closes a populated cache and checks that the entries map is empty and size is zero.

Changes

Slow plan cache close cleanup

Layer / File(s) Summary
Close clears cached entries
router/pkg/slowplancache/slow_plan_cache.go, router/pkg/slowplancache/slow_plan_cache_test.go
Cache.Close() deletes all stored entries from c.entries after writeCh is closed and resets c.size; the new test populates the cache, closes it, and verifies both post-close conditions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: clearing slow plan cache entries during Close().
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.08%. Comparing base (5efb3c2) to head (6b68dae).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3006      +/-   ##
==========================================
- Coverage   60.27%   54.08%   -6.20%     
==========================================
  Files         477      243     -234     
  Lines       62471    29469   -33002     
  Branches     6131        0    -6131     
==========================================
- Hits        37656    15939   -21717     
+ Misses      24787    11947   -12840     
- Partials       28     1583    +1555     
Files with missing lines Coverage Δ
router/pkg/slowplancache/slow_plan_cache.go 57.69% <100.00%> (ø)

... and 719 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dkorittki

Copy link
Copy Markdown
Contributor

Closing this PR because this is now handled in #3023

@dkorittki dkorittki closed this Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants