Avoid plug loading race condition
parent
9921d72b96
commit
0475c4c40e
|
@ -23,6 +23,7 @@ export class KVPrimitivesManifestCache<T> implements ManifestCache<T> {
|
||||||
const manifest = plug.sandbox.manifest!;
|
const manifest = plug.sandbox.manifest!;
|
||||||
await this.kv.batchSet([{
|
await this.kv.batchSet([{
|
||||||
key: [this.manifestPrefix, plug.name],
|
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 },
|
value: { manifest: { ...manifest, assets: undefined }, hash },
|
||||||
}]);
|
}]);
|
||||||
return manifest;
|
return manifest;
|
||||||
|
@ -43,7 +44,11 @@ export class InMemoryManifestCache<T> implements ManifestCache<T> {
|
||||||
}
|
}
|
||||||
await plug.sandbox.init();
|
await plug.sandbox.init();
|
||||||
const manifest = plug.sandbox.manifest!;
|
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;
|
return manifest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,9 @@ export class Sandbox<HookT> {
|
||||||
init(): Promise<void> {
|
init(): Promise<void> {
|
||||||
console.log("Booting up worker for", this.plug.name);
|
console.log("Booting up worker for", this.plug.name);
|
||||||
if (this.worker) {
|
if (this.worker) {
|
||||||
// Should not happen
|
// Race condition
|
||||||
console.warn("Double init of sandbox");
|
console.warn("Double init of sandbox, ignoring");
|
||||||
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
this.worker = new Worker(this.plug.workerUrl, {
|
this.worker = new Worker(this.plug.workerUrl, {
|
||||||
...this.workerOptions,
|
...this.workerOptions,
|
||||||
|
|
Loading…
Reference in New Issue