Skip to content

Commit 0f907f5

Browse files
authored
Merge pull request #6428 from cloudflare/dominik/EW-10700
Don't throw when dedicated snapshot is missing in dynamic workers.
2 parents 0d830b1 + 550daf0 commit 0f907f5

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/pyodide/internal/metadata.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const SHOULD_SNAPSHOT_TO_DISK = MetadataReader.shouldSnapshotToDisk();
1313
export const IS_CREATING_BASELINE_SNAPSHOT =
1414
MetadataReader.isCreatingBaselineSnapshot();
1515
export const IS_EW_VALIDATING = ArtifactBundler.isEwValidating();
16+
export const IS_DYNAMIC_WORKER = ArtifactBundler.isDynamicWorker();
1617
export const IS_CREATING_SNAPSHOT = IS_EW_VALIDATING || SHOULD_SNAPSHOT_TO_DISK;
1718

1819
// There are two validations that we perform. The first one runs without a _bundled_ memory snapshot

src/pyodide/internal/snapshot.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
REQUIREMENTS,
1616
IS_CREATING_SNAPSHOT,
1717
IS_EW_VALIDATING,
18+
IS_DYNAMIC_WORKER,
1819
IS_DEDICATED_SNAPSHOT_ENABLED,
1920
COMPATIBILITY_FLAGS,
2021
type CompatibilityFlags,
@@ -763,6 +764,12 @@ function checkSnapshotType(snapshotType: string): void {
763764
if (SHOULD_SNAPSHOT_TO_DISK) {
764765
return;
765766
}
767+
// Dynamic workers don't yet support dedicated snapshots, so they will receive a baseline
768+
// snapshot from GCS even when the dedicated snapshot compat flag is enabled. Skip the
769+
// snapshot type validation in this case.
770+
if (IS_DYNAMIC_WORKER) {
771+
return;
772+
}
766773
if (
767774
!IS_EW_VALIDATING &&
768775
snapshotType === 'dedicated' &&

src/pyodide/types/artifacts.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ declare namespace ArtifactBundler {
1212

1313
const hasMemorySnapshot: () => boolean;
1414
const isEwValidating: () => boolean;
15+
const isDynamicWorker: () => boolean;
1516
const readMemorySnapshot: (
1617
offset: number,
1718
buf: Uint32Array | Uint8Array

src/workerd/api/pyodide/pyodide.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,19 +319,25 @@ struct ArtifactBundler_State {
319319
// to store a memory snapshot.
320320
bool isValidating;
321321

322+
// Set when the worker is a dynamically-loaded worker. Dynamic workers don't support dedicated
323+
// snapshots yet, so the Python runtime uses this to skip snapshot type validation.
324+
bool isDynamicWorkerFlag;
325+
322326
ArtifactBundler_State(kj::Maybe<const PyodidePackageManager&> packageManager,
323327
kj::Maybe<kj::Array<const kj::byte>> existingSnapshot,
324-
bool isValidating = false)
328+
bool isValidating = false,
329+
bool isDynamicWorker = false)
325330
: packageManager(packageManager),
326331
storedSnapshot(kj::none),
327332
existingSnapshot(kj::mv(existingSnapshot)),
328-
isValidating(isValidating) {};
333+
isValidating(isValidating),
334+
isDynamicWorkerFlag(isDynamicWorker) {};
329335

330336
kj::Own<ArtifactBundler_State> clone() {
331337
return kj::heap<ArtifactBundler_State>(packageManager,
332338
existingSnapshot.map(
333339
[](kj::Array<const kj::byte>& data) { return kj::heapArray<const kj::byte>(data); }),
334-
isValidating);
340+
isValidating, isDynamicWorkerFlag);
335341
}
336342
};
337343

@@ -369,6 +375,11 @@ class ArtifactBundler: public jsg::Object {
369375
return inner->isValidating;
370376
}
371377

378+
// Determines whether this ArtifactBundler belongs to a dynamically-loaded worker.
379+
bool isDynamicWorker() {
380+
return inner->isDynamicWorkerFlag;
381+
}
382+
372383
static kj::Own<State> makeDisabledBundler() {
373384
return kj::heap<State>(kj::none, kj::none);
374385
}
@@ -404,6 +415,7 @@ class ArtifactBundler: public jsg::Object {
404415
JSG_METHOD(readMemorySnapshot);
405416
JSG_METHOD(disposeMemorySnapshot);
406417
JSG_METHOD(isEwValidating);
418+
JSG_METHOD(isDynamicWorker);
407419
JSG_METHOD(storeMemorySnapshot);
408420
JSG_METHOD(isEnabled);
409421
JSG_METHOD(getPackage);

0 commit comments

Comments
 (0)