Skip to content

Bound vmcp health and session registry growth - #6667

Closed
lorenzozanee wants to merge 1 commit into
stacklok:mainfrom
lorenzozanee:restore/pr-6450
Closed

lorenzozanee wants to merge 1 commit into
stacklok:mainfrom
lorenzozanee:restore/pr-6450

Conversation

@lorenzozanee

Copy link
Copy Markdown
Contributor

Summary

All VirtualMCPServer instances grow 2-3x RSS over ~24h, scaling with backend count (12/13/14/19 backends grew 2.0-3.1x vs flat control proxies). Investigation shows two unbounded in-memory maps:

  • health.statusTracker.removedBackends kept a tombstone per removed backend forever to avoid in-flight health-check races. Under ID churn it grew linearly without expiry.
  • server.healthResyncRegistry kept a per-session listChangedResyncWorker (holding ClientSession + identity) for sessions that ended via TTL expiry. Pruning only happened on the next async resync, so the registry stayed larger than the live session set between health-change events.

What changed:

  • Bound removedBackends with a TTL of 2*checkInterval (default 60s, 5m fallback). Entries expire lazily on isRemoved and are pruned periodically in UpdateBackends and performHealthCheck, and proactively at RemoveBackend insertion.
  • Filter dead sessions synchronously at health-change fan-out: snapshot now returns a map, resyncSessionsOnBackendHealthChange checks GetMultiSession for each entry and removes dead sessions before triggering, keeping |workers| == |liveSessions|.

Fixes #5860

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

New regression tests:

  • pkg/vmcp/server/regression_5860_health_resync_test.go: verifies fan-out prunes dead sessions and only triggers live sessions (fails on base with 4 workers vs 2 live).
  • pkg/vmcp/health/regression_5860_tombstone_test.go: churns 50 distinct backends and asserts tombstones are bounded after TTL (fails on base with 50 entries).

Existing pkg/vmcp/health and pkg/vmcp/server suites pass (task test with -race).

API Compatibility

  • This PR does not break the v1beta1 API, OR the api-break-allowed label is applied and the migration guidance is described above.

Changes

File Change
pkg/vmcp/health/status.go map[string]bool -> map[string]time.Time with TTL, lazy and periodic prune
pkg/vmcp/health/monitor.go Inject checkInterval, prune in UpdateBackends/performHealthCheck
pkg/vmcp/server/serve_health_resync.go snapshot map, synchronous GetMultiSession filter at fan-out
pkg/vmcp/server/serve_health_resync_test.go Adapt coalescing test to new filter path
pkg/vmcp/health/regression_5860_tombstone_test.go New bounded-tombstone regression
pkg/vmcp/server/regression_5860_health_resync_test.go New bounded-registry regression

Supersedes #6450 (原PR分支已删,按原提交重建)

@aponcedeleonch

Copy link
Copy Markdown
Member

Sorry for the slow response on this one, @lorenzozanee, and thanks for the work here. We're going to close this PR, though. #5860 is assigned to @RaviTharuma, and the discussion there settled on a different fix: a sweep that reclaims session cache entries once their stored metadata has expired, without renewing the TTL. This PR bounds the health tombstones and the resync registry instead, and as @alex-feel noted on the issue, that isn't expected to change the memory growth reported there. It also says Fixes #5860, so merging it would close the issue before the agreed fix lands.

Our contributing guide asks contributors to comment on an issue, wait to be assigned, and follow the approach agreed there before opening a PR. If you think the tombstone and registry bounds are worth fixing on their own, please open a separate issue describing what you've seen, and we can take it from there. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vmcp: all VirtualMCPServer instances grow 2-3x in memory over ~24h regardless of client activity

2 participants