You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(interp): release the arguments a rejected finalizer call encodes - #344
A Go func bound to a VM function encodes its arguments before invoke copies them to the operand stack. The finalizer guard merged in #342 rejects that call before the copy, and the error path returned without releasing the refs Encoder.retain and Encoder.alloc published, so every callback a Close made on a string or ref argument left one more object alive. The other pre-copy rejections (ErrInterpreterBusy, ErrFrameOverflow, ErrTypeMismatch, ErrStackOverflow) leaked the same way.
interp/interp.go: invoke now takes params. Its refusals are decided in one switch, and the single refusal branch releases the arguments, so a refused call returns the heap as it found it and a started call releases the arguments with the stack — each reference is released exactly once on every path. The callee reference is resolved before the arguments reach the stack, so nothing fails once the stack holds them; that ordering also removes the previous Alloc-failure path, which had copied the arguments first and then abandoned them. Everything stays inside invoke: the change adds no helper, no state flag, and no transfer hook on Encoder (a conversion's result already owns the refs it published, so once the argument boxes are in params the Go caller owns them and hands them to invoke).
interp/interp_test.go: a regression test calls a Go func bound to a VM function from a Close and asserts the rejected call's string argument leaves no live heap value behind. It fails on main with one leaked count per call and passes here.
Related Issues
Follow-up to the CodeRabbit review comment on #342 at interp/interp.go:818-819 (release the encoded arguments when the finalizer guard rejects the callback).
Additional Information
go test ./... and the benchmarks module pass on the pinned Go 1.26.2, and ./interp ./types pass on Go 1.27.4.
go vet ./..., gofmt -l ., go run ./internal/cmd/codegen -check, GOOS=linux GOARCH=arm64 go build ./..., GOARCH=arm64 go test -exec=true ./..., the check-inline gate, and git diff --check are clean.
-race needs cgo, which the environment this was prepared in does not have, so CI is the first race run.
invoke has a single caller (Registry.unmarshalFunc), so no other caller's ownership changes.
Summary by CodeRabbit
Bug Fixes
Improved cleanup when host calls are rejected due to interpreter state or capacity limits, releasing transferred parameters and preventing retained values from accumulating in the heap.
Documentation
Updated benchmark results with revised timing, allocation, and JIT speedup measurements.
This repository does not receive automatic reviews because it has fewer than 10 stars.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: eb8d598c-28e1-4a6a-8f1c-8c3aa8ac55e4
No actionable comments were generated in the recent review.
Walkthrough
Interpreter.invoke now releases transferred parameter references when invocation fails before stack transfer. A regression test checks cleanup after a finalizer-triggered host call. The benchmark table has updated measurements, and a blank line was removed from interp/codec.go.
Changes: Argument ownership
Layer / File(s)
Summary
Argument transfer and cleanup interp/interp.go, interp/interp_test.go, interp/codec.go
invoke releases parameter references on failure before stack transfer. A test checks cleanup when a finalizer-triggered host call is rejected. interp/codec.go has one blank line removed.
Benchmark measurements
Layer / File(s)
Summary
Updated benchmark results docs/benchmarks.md
The table records revised timings, allocation counts, and JIT speedups. Its runtime columns and kernel rows remain unchanged.
This change fixes a leak of encoded arguments when a bound Go function call from a finalizer is rejected, and a regression test covers it. No merge-blocking issues remain.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: invoke releases the arguments that a rejected finalizer call encodes. The raw summary and the PR objectives both describe this fix in interp/interp.go. The title uses …
Description check
The description follows the template. Changes Made lists the edits in interp/interp.go and interp/interp_test.go with reasoning. Related Issues references the follow-up to the CodeRabbit review commen…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: invoke releases the arguments that a rejected finalizer call encodes. The raw summary and the PR objectives both describe this fix in interp/interp.go. The title uses the conventional fix(interp) prefix and is specific enough for a teammate scanning history.
Full details: Description check
Explanation
The description follows the template. Changes Made lists the edits in interp/interp.go and interp/interp_test.go with reasoning. Related Issues references the follow-up to the CodeRabbit review comment on #342. Additional Information lists validation commands and notes that -race was not run. The description is detailed and specific. It does not follow the template's HTML comment placeholders exactly, but it has all three sections with the required content.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 3b3a9d64-c5f2-4415-a005-237f82cbc01d
Commits
Reviewing files that changed from the base of the PR and between eca5567 and c325e99.
Files selected for processing: 4
docs/benchmarks.md
interp/codec.go
interp/interp.go
interp/interp_test.go
Files with no reviewable changes: 1
interp/codec.go
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
A Go func bound to a VM function encodes its arguments before invoke copies
them to the stack. The finalizer guard merged in #342 rejects the call before
that copy, and the error path left every ref Encoder.retain and Encoder.alloc
published in the heap, so repeated callbacks from a Close grew the heap. The
other pre-copy rejections leaked the same way.
invoke now takes params: its refusals share one point that releases them, so a
refused call returns the heap as it found it and a started call releases the
arguments with the stack. The callee reference is resolved before the arguments
reach the stack, so nothing fails once the stack holds them.
Refs #342
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
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.
A Go func bound to a VM function encodes its arguments before
invokecopies them to the operand stack. The finalizer guard merged in #342 rejects that call before the copy, and the error path returned without releasing the refsEncoder.retainandEncoder.allocpublished, so every callback aClosemade on a string or ref argument left one more object alive. The other pre-copy rejections (ErrInterpreterBusy,ErrFrameOverflow,ErrTypeMismatch,ErrStackOverflow) leaked the same way.interp/interp.go:invokenow takesparams. Its refusals are decided in one switch, and the single refusal branch releases the arguments, so a refused call returns the heap as it found it and a started call releases the arguments with the stack — each reference is released exactly once on every path. The callee reference is resolved before the arguments reach the stack, so nothing fails once the stack holds them; that ordering also removes the previousAlloc-failure path, which had copied the arguments first and then abandoned them. Everything stays insideinvoke: the change adds no helper, no state flag, and no transfer hook onEncoder(a conversion's result already owns the refs it published, so once the argument boxes are inparamsthe Go caller owns them and hands them toinvoke).interp/interp_test.go: a regression test calls a Go func bound to a VM function from aCloseand asserts the rejected call's string argument leaves no live heap value behind. It fails onmainwith one leaked count per call and passes here.Related Issues
Follow-up to the CodeRabbit review comment on #342 at
interp/interp.go:818-819(release the encoded arguments when the finalizer guard rejects the callback).Additional Information
go test ./...and thebenchmarksmodule pass on the pinned Go 1.26.2, and./interp ./typespass on Go 1.27.4.go vet ./...,gofmt -l .,go run ./internal/cmd/codegen -check,GOOS=linux GOARCH=arm64 go build ./...,GOARCH=arm64 go test -exec=true ./..., thecheck-inlinegate, andgit diff --checkare clean.-raceneeds cgo, which the environment this was prepared in does not have, so CI is the first race run.invokehas a single caller (Registry.unmarshalFunc), so no other caller's ownership changes.Summary by CodeRabbit