Skip to content

fix(interp): release the arguments a rejected finalizer call encodes - #344

Merged
siyul-park merged 6 commits into
mainfrom
fix/invoke-finalizer-args
Nov 17, 2026
Merged

siyul-park merged 6 commits into
mainfrom
fix/invoke-finalizer-args

Conversation

@siyul-park

@siyul-park siyul-park commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

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.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

  • Trigger review

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.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · previous review c325e

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 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.
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.

Share

Recent review info

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: 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.

@siyul-park
siyul-park force-pushed the fix/invoke-finalizer-args branch from e222fff to ec8e472 Compare November 16, 2026 15:46
siyul-park and others added 3 commits November 17, 2026 01:02
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
@siyul-park
siyul-park force-pushed the fix/invoke-finalizer-args branch from 130c910 to 1f69d9b Compare November 16, 2026 16:03
@siyul-park
siyul-park merged commit af86a70 into main Nov 17, 2026
2 checks passed
@siyul-park
siyul-park deleted the fix/invoke-finalizer-args branch November 17, 2026 14:46
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.

1 participant