Skip to content

Make async GC lifetime assertions deterministic - #392

Merged
akeit0 merged 1 commit into
mainfrom
codex/fix-gc-lifetime-assertion
Oct 29, 2026
Merged

akeit0 merged 1 commit into
mainfrom
codex/fix-gc-lifetime-assertion

Conversation

@akeit0

@akeit0 akeit0 commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

The GC lifetime assertions could run after task completion but before the completing callback had unwound. That callback could still root its async state machine and captured payload even though Lua had already cleared its stack and frames.

Use a one-shot manual suspension in the exception and VM-context lifetime tests. It preserves genuine async suspension and returns from the resumed continuation before collecting. Remove the VM-context test's polling assertion. Production code is unchanged.

Validation:

  • A controlled reproduction on .NET 8 and .NET 10 confirms the payload becomes collectible when the dispatched callback is released.
  • All 42 focused lifetime cases pass on each framework.
  • All 2,585 runtime tests pass on each framework in Release.
  • CSharpier and git diff --check pass.

No sleeps or retries are used by the updated tests.

Task completion can wake a blocking consumer while the dispatched async
callback still holds its state machine and captured payload. A controlled
.NET 8/10 reproduction confirms that Lua frames and stack are already
empty, and releasing the callback makes the payload collectible.

Use a one-shot manual suspension in exception and VM-context lifetime
tests so the resumed continuation returns before collection. Preserve
actual async suspension and immediate weak-reference assertions, and
remove the VM-context test's polling assertion. Production code is
unchanged.

Validation: 42 focused cases and all 2,585 runtime tests pass on each of
.NET 8 and .NET 10 in Release. CSharpier and git diff --check pass.
@akeit0
akeit0 merged commit 4e41b71 into main Oct 29, 2026
2 checks passed
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