Skip to content

Remove C# resource table entries once they're released - #2098

Open
ludfjig wants to merge 1 commit into
hyperlight-dev:mainfrom
ludfjig:fix-csharp-resource-table
Open

ludfjig wants to merge 1 commit into
hyperlight-dev:mainfrom
ludfjig:fix-csharp-resource-table

Conversation

@ludfjig

@ludfjig ludfjig commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

ResourceTable<T> in the C# component runtime keeps an entry for every Give and Lend, so a long-lived sandbox that passes resources grows without bound.

This stores entries in a dictionary keyed by an increasing counter and removes them on Take, at the end of a loan and when a gift is undone. Handles are never reused.

Fixes #2056

ResourceTable kept an entry for every handle given to or lent to the guest, so a long-lived sandbox that passed resources grew without bound. Entries now live in a dictionary keyed by an increasing counter. Take, the end of a loan and an undone gift remove them. Handles are still never reused.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the C# resource-table cleanup change.

No open issues 🎉

What changed in this PR

This PR addresses #2056 by removing released entries from Hyperlight’s C# resource table, preventing entry accumulation across calls in long-lived sandboxes.

Changes:

  • A dictionary stores resources under increasing handles that are never reused.
  • Ownership returns, completed loans, and gift rollback remove entries.
  • Runtime tests cover cleanup, loan ownership checks, stale handles, and handle non-reuse.
File Description
src/​tests/​csharp_host/​RuntimeTests.cs Verifies entry removal and handle lifecycle behavior.
src/​hyperlight_component_csharp/​src/​Runtime.cs Implements dictionary-backed resource storage and entry removal.
CHANGELOG.md Documents the C# resource-table retention fix.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-bug For PRs that fix bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C# ResourceTable never frees entries

2 participants