Skip to content

Commit

Permalink
Merge pull request #3491 from cloudflare/dominik/check-fetch-status
Browse files Browse the repository at this point in the history
Check HTTP status code when fetching Py pkg/bundle.
  • Loading branch information
dom96 authored Feb 7, 2025
2 parents e05e134 + 1159921 commit acb326f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/pyodide/internal/loadPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ async function loadBundleFromR2(requirement: string): Promise<Reader> {
// we didn't find it in the disk cache, continue with original fetch
const url = new URL(WORKERD_INDEX_URL + filename);
const response = await fetch(url);
if (response.status != 200) {
throw new Error(
'Could not fetch package at url ' +
url +
' received status ' +
response.status
);
}

original = await response.arrayBuffer();
DiskCache.put(filename, original);
Expand Down
6 changes: 5 additions & 1 deletion src/workerd/server/workerd-api.c++
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ kj::Maybe<jsg::Bundle::Reader> fetchPyodideBundle(
}

{
KJ_LOG(INFO, "Loading Pyodide package from internet...");
KJ_LOG(INFO, "Loading Pyodide bundle from internet...");
kj::Thread([&]() {
kj::AsyncIoContext io = kj::setupAsyncIo();
kj::HttpHeaderTable table;
Expand All @@ -200,13 +200,17 @@ kj::Maybe<jsg::Bundle::Reader> fetchPyodideBundle(

kj::HttpHeaders headers(table);

// TODO: Point this at our production R2 bucket.
kj::String url =
kj::str("https://pyodide.runtime-playground.workers.dev/pyodide-capnp-bin/pyodide_",
version, ".capnp.bin");

auto req = client->request(kj::HttpMethod::GET, url.asPtr(), headers);

auto res = req.response.wait(io.waitScope);
KJ_ASSERT(res.statusCode == 200,
kj::str(
"Request for Pyodide bundle at ", url, " failed with HTTP status ", res.statusCode));
auto body = res.body->readAllBytes().wait(io.waitScope);

writePyodideBundleFileToDisk(pyConfig.pyodideDiskCacheRoot, version, body);
Expand Down

0 comments on commit acb326f

Please sign in to comment.