Repository navigation
fix(vm): release the store when Exec returns so a reused VM does not retain it - #211
Merged
Merged
Conversation
NumaryBot
approved these changes
Oct 5, 2026
NumaryBot
left a comment
Contributor
There was a problem hiding this comment.
The required automated review completed with no remaining findings.
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.
Problem
vm.Execbinds the caller's store into the VM'sRunStateand only replaces it at the next execution. A VM that is kept and reused (the intended usage: the ledger caches one warm VM per script) therefore keeps its last run's store — and everything that store references — reachable afterExecreturns.In the ledger, that store reaches the apply scope of the Raft proposal that ran the script, including the whole preloaded coverage plan, so each cached VM pins an old proposal until the same script runs again or the entry is evicted.
Fix
Execnow defersrunstate.Reset(nil): on every exit (success, execution error, or a panic raised by the store) the store is released along with the per-run balances. Results are unaffected —GetPostingsalready returns copies taken before the deferred reset.Tests
TestExecVmReleasesStoreholds a weak pointer to the store and checks it becomes collectable while the VM is still alive, for the success, error and store-panic exits. It fails on all three without the fix.go test ./..., race on the touched packages, andgolangci-lintare clean.Performance
No measurable change (
BenchmarkCompiledVM,BenchmarkCompiledVMCapped,BenchmarkCompiledVMFanIn, 5 runs each): identical allocations, timings within noise.