Skip to content

Conversation

@sirtimid
Copy link
Contributor

This patch closes the last reference‑count leaks that left fulfilled promises and exported root objects in the store after vats were terminated or the kernel was restarted, ensuring the run‑queue, promises, and object graphs now cleanly reach zero and are fully reclaimed by GC.

@sirtimid sirtimid requested a review from a team as a code owner April 22, 2025 16:06
@sirtimid sirtimid enabled auto-merge (squash) April 22, 2025 16:15
@sirtimid sirtimid disabled auto-merge April 22, 2025 16:28
@sirtimid sirtimid force-pushed the sirtimid/fix-lingering-ref-counts-gc branch from 123a57b to 4ab5b1c Compare April 22, 2025 18:02
Copy link
Contributor

@FUDCo FUDCo left a comment

Choose a reason for hiding this comment

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

Mostly excellent. One possible anti-leak that needs to be either fixed or explained.

await this.#runVat(vatId, vatConfig);
this.#kernelStore.initEndpoint(vatId);
const rootRef = this.#kernelStore.exportFromVat(vatId, ROOT_OBJECT_VREF);
this.#kernelStore.incrementRefCount(rootRef, 'root');
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to pin every root ref (in fact, we absolutely shouldn't) but something like this has to happen somewhere (perhaps launchSubcluster?) to ensure that references (e.g., to bootstrap vats) that are only held externally (e.g., by the control panel or test scripts) but never explicitly exported via a message parameter are counted, else one's whole subcluster could simply disappear after a GC. (Speaking cosmologically, the universe as a whole is unreferenced.). This can sneak up on you (ask me how I know :-)

Copy link
Contributor Author

@sirtimid sirtimid Apr 22, 2025

Choose a reason for hiding this comment

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

I pinky swear that a whole subcluster can't disappear except if one deletes the bootstrap vat after they have deleted all the other vats and have garbage collected them. Shouldn't we support this process? One can't just delete all vats (with the bootstrap) and garbage collect them, the references brake. In other words: the requirement that you retire the secondary vats before you retire the bootstrap is what guarantees safety imo.

Anyway I suggest we do this on another "add removable bootstrap keep‑alive pin" task and perhaps follow agorics convention of pin/unpin. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, that that sounds like the right plan to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, subtle point:
It's not that the vat itself gets GC'd, it's that the vat's root object gets GC'd, so unless the vat has in the meantime wired itself up with other vats you lose the ability to talk to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And.. done #494

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, as a general rule, GC'ing a vat's root object while the rest of the vat continues to run is not a problem. At Agoric, it was not uncommon to create a vat with an ephemeral root object whose only job was to initialize things and then go away.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha! I didn't expect that, but, yes of course, why not!

@sirtimid sirtimid requested review from FUDCo and rekmarks April 22, 2025 19:49
Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

@sirtimid you use "credit" in promise.ts and vat.ts also.

@sirtimid sirtimid requested a review from rekmarks April 22, 2025 20:17
@sirtimid
Copy link
Contributor Author

sirtimid commented Apr 22, 2025

@sirtimid you use "credit" in promise.ts and vat.ts also.

argg.. fixed. @rekmarks

Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@FUDCo FUDCo left a comment

Choose a reason for hiding this comment

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

Plug your ears...

@sirtimid sirtimid merged commit 690dec0 into main Apr 22, 2025
21 checks passed
@sirtimid sirtimid deleted the sirtimid/fix-lingering-ref-counts-gc branch April 22, 2025 20:33
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.

4 participants