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.
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: a6877560-c4f0-4f03-aaf9-8b10ad87dd39
No actionable comments were generated in the recent review.
Walkthrough
The VM function adapter transfers boxed argument ownership before invocation. The interpreter releases arguments when invocation returns before the operand stack takes ownership. A regression test checks heap-reference cleanup when a finalizer call is rejected.
Changes: Argument ownership
Layer / File(s)
Summary
Argument transfer and cleanup interp/encode.go, interp/codec.go, interp/interp.go, interp/interp_test.go
Encoder.transfer clears the encoder’s owned-reference list without releasing its references. The adapter transfers boxed arguments before invocation. invoke releases parameters if execution returns before the operand stack takes ownership, and the added regression test checks cleanup after a rejected finalizer call.
This change fixes a leak of heap references when a finalizer call into a VM function is rejected. No concrete merge-blocking risk was found, and a regression test covers the rejected-call case.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the fix and its scope: releasing the encoded arguments when a rejected finalizer call fails. The changeset matches this. The summaries show ownership changes in invoke, Encoder.transfe…
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.
Description check
The description follows the repository template: it has Changes Made, Related Issues, and Additional Information sections. It explains the leak (refs from Encoder.retain and Encoder.alloc are not rele…
Full details: Title check
Explanation
The title names the fix and its scope: releasing the encoded arguments when a rejected finalizer call fails. The changeset matches this. The summaries show ownership changes in invoke, Encoder.transfer, and codec.go, plus a regression test for a rejected finalizer-bound call. The title is specific and follows the conventional-commit style. It does not cover the broader pre-copy rejection paths, but that detail is not required.
Full details: Description check
Explanation
The description follows the repository template: it has Changes Made, Related Issues, and Additional Information sections. It explains the leak (refs from Encoder.retain and Encoder.alloc are not released on pre-copy rejections of invoke), lists the changed files in interp/interp.go and interp/interp_test.go, links the follow-up to the CodeRabbit review comment on #342, and reports the test and lint results. The description is specific and matches the raw summary. One gap: the description says Encoder.transfer is not added, while the raw summary lists encode.go with a new Encoder.transfer method. The description omits interp/codec.go and interp/encode.go from its file list, so the description and the file-level summary do not fully agree.
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: 3960f4b9-e376-4f97-a17a-a5c7dda62b1b
Commits
Reviewing files that changed from the base of the PR and between 87c13d1 and eca5567.
Files selected for processing: 4
interp/codec.go
interp/encode.go
interp/interp.go
interp/interp_test.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.