Skip to content

Commit 59e4dd3

Browse files
committed
fix(swingset): recreateDynamicVat() waits for vat creation
We have three functions in `loadVat.js` to create a vat. `createVatDynamically()`is used to create a dynamic vat for the first time. It does not wait for the vat to be created, but instead returns the newly-allocated vatID synchronously, so the vatAdminVat which invoked it (via a device) can learn the vatID to wait for. recreateStaticVat() and recreateDynamicVat() are used during kernel reboot to reload vats created by the earlier instance. recreateStaticVat() returns a Promise that fires when the vat is fully loaded (which includes evaluating the source bundle). recreateDynamicVat() was not returning a Promise, rather it followed the pattern of `createVatDynamically()` and returned a synchronous vatID. The code in `kernel.js` which called it was using `await`, as if it returned a Promise. As a result, rebooting a kernel with multiple dynamic vats would attempt to reload those vats in parallel. These vat reloads currently each take ~20s (for a dynamic ZCF vat with metering enabled), and are CPU bound, and the engine isn't multithreaded, so they do not benefit from parallelism (this will change when we have each vat in a separate subprocess). Also, the accidental parallelism interferes with attempts to measure the time each reload takes (to guide optimization efforts). This changes `recreateDynamicVat` to return the same sort of Promise that `recreateStaticVat` does. closes #2871
1 parent e382073 commit 59e4dd3

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

packages/SwingSet/src/kernel/loadVat.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,11 @@ export function makeVatLoader(stuff) {
5555
* @param {*} source The source object implementing the vat
5656
* @param {*} dynamicOptions Options bag governing vat creation
5757
*
58-
* @returns {string} The vatID of the vat
58+
* @returns {Promise<void>} fires when the vat is ready for messages
5959
*/
6060
function recreateDynamicVat(vatID, source, dynamicOptions) {
6161
// eslint-disable-next-line no-use-before-define
62-
create(vatID, source, dynamicOptions, false, true);
63-
// again we ignore create()'s Promise
64-
return vatID;
62+
return create(vatID, source, dynamicOptions, false, true);
6563
}
6664

6765
/**

0 commit comments

Comments
 (0)