Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(liveslots): avoid slotToVal memory leak for watched promises #10758

Merged
merged 2 commits into from
Dec 21, 2024

Conversation

warner
Copy link
Member

@warner warner commented Dec 20, 2024

Liveslots has a bug (#10757) which leaks slotToVal entries when a tracked Promise is still being held in virtual data (e.g. a merely-virtual MapStore) at the time it becomes settled. This is triggered by watchPromise because of the order in which we attach two handlers: one which notices the resolution and is inhibited from deleting the slotToVal entry, and a second which removes the Promise from the (virtual) promiseRegistrations collection (thus enabling the deletion). For any watched Promise that is resolved, we leave a slotToVal entry (with an empty WeakRef) in RAM until the end of the incarnation.

This PR does not fix the underlying bug, but it rearranges the handler order to avoid triggering it.

The attached unit test fails with the original handler order (slotToVal.size grows), and passes with the swapped order (slotToVal.size remains constant).

closes #10756
refs #10706

@warner warner added SwingSet package: SwingSet liveslots requires vat-upgrade to deploy changes labels Dec 20, 2024
@warner warner requested a review from mhofman December 20, 2024 21:11
@warner warner requested a review from a team as a code owner December 20, 2024 21:11
Copy link

cloudflare-workers-and-pages bot commented Dec 20, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 874196c
Status: ✅  Deploy successful!
Preview URL: https://fd81452b.agoric-sdk.pages.dev
Branch Preview URL: https://10756-watch-promise-leak.agoric-sdk.pages.dev

View logs

@toliaqat toliaqat requested a review from gibson042 December 20, 2024 21:15
packages/swingset-liveslots/src/watchedPromises.js Outdated Show resolved Hide resolved
packages/swingset-liveslots/test/watch-promise.test.js Outdated Show resolved Hide resolved
Liveslots has a bug (#10757) which leaks slotToVal entries when a
tracked Promise is still being held in virtual data (e.g. a
merely-virtual MapStore) at the time it becomes settled. This is
triggered by `watchPromise` because of the order in which we attach
two handlers: one which notices the resolution and is inhibited from
deleting the slotToVal entry, and a second which removes the Promise
from the (virtual) `promiseRegistrations` collection (thus enabling
the deletion). For any watched Promise that is resolved, we leave a
`slotToVal` entry (with an empty WeakRef) in RAM until the end of the
incarnation.

This commit adds a test.failing to demonstrate the presence of the
bug. Each time we watch and then resolve a promise, the slotToVal
table grows by one entry.

refs #10756
Liveslots has a bug (#10757) which leaks slotToVal entries when a
tracked Promise is still being held in virtual data (e.g. a
merely-virtual MapStore) at the time it becomes settled. This is
triggered by `watchPromise` because of the order in which we attach
two handlers: one which notices the resolution and is inhibited from
deleting the slotToVal entry, and a second which removes the Promise
from the (virtual) `promiseRegistrations` collection (thus enabling
the deletion). For any watched Promise that is resolved, we leave a
`slotToVal` entry (with an empty WeakRef) in RAM until the end of the
incarnation.

This PR does not fix the underlying bug, but it rearranges the handler
order to avoid triggering it.

closes #10756
refs #10706
@warner warner force-pushed the 10756-watch-promise-leak branch from bec3f6e to 874196c Compare December 20, 2024 23:49
@warner warner added the automerge:rebase Automatically rebase updates, then merge label Dec 20, 2024
@mergify mergify bot merged commit 4472050 into master Dec 21, 2024
91 checks passed
@mergify mergify bot deleted the 10756-watch-promise-leak branch December 21, 2024 00:40
mergify bot added a commit that referenced this pull request Dec 24, 2024
refs: #10758, #10756
closes: #10762

## Description

Upgrade the Orchestration (both Core and API) vats to use liveslots with the #10758 fix for a `watchPromise` memory leak (#10756).

### Security Considerations

No code change to the vat user code in question, just to the liveslots it relies on.

### Scaling Considerations

Should flatten the memory growth curve.

### Documentation Considerations

No changes to existing data.

### Testing Considerations

The upgraded vats should be monitored for memory growth.

### Upgrade Considerations

n/a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge liveslots requires vat-upgrade to deploy changes SwingSet package: SwingSet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

liveslots doesn't drop WatchedPromises from slotToVal
5 participants