1
0

Avoid plug loading race condition

This commit is contained in:
Zef Hemel 2023-12-10 15:18:34 +01:00
parent 9921d72b96
commit 0475c4c40e
2 changed files with 9 additions and 3 deletions

View File

@ -23,6 +23,7 @@ export class KVPrimitivesManifestCache<T> implements ManifestCache<T> {
const manifest = plug.sandbox.manifest!;
await this.kv.batchSet([{
key: [this.manifestPrefix, plug.name],
// Deliverately removing the assets from the manifest to preserve space, will be re-added upon load of actual worker
value: { manifest: { ...manifest, assets: undefined }, hash },
}]);
return manifest;
@ -43,7 +44,11 @@ export class InMemoryManifestCache<T> implements ManifestCache<T> {
}
await plug.sandbox.init();
const manifest = plug.sandbox.manifest!;
this.cache.set(plug.name!, { manifest, hash });
// Deliverately removing the assets from the manifest to preserve space, will be re-added upon load of actual worker
this.cache.set(plug.name!, {
manifest: { ...manifest, assets: undefined },
hash,
});
return manifest;
}
}

View File

@ -32,8 +32,9 @@ export class Sandbox<HookT> {
init(): Promise<void> {
console.log("Booting up worker for", this.plug.name);
if (this.worker) {
// Should not happen
console.warn("Double init of sandbox");
// Race condition
console.warn("Double init of sandbox, ignoring");
return Promise.resolve();
}
this.worker = new Worker(this.plug.workerUrl, {
...this.workerOptions,