Skip to content

translateToHttpUrl uses the global S3 endpoint for dotted buckets → 301 (not followed) for non-us-east-1, breaking virtual chunk reads #25

Closed

Description

@tylere

Summary

translateToHttpUrl maps an s3://<bucket>/<key> virtual-chunk location whose bucket name contains a dot to the path-style global endpoint https://s3.amazonaws.com/<bucket>/<key>. For a bucket that lives outside us-east-1, the global endpoint answers 301 Moved Permanently (redirecting to the regional host). The virtual-chunk fetch treats any non-200/206 response as a hard error and does not follow the redirect, so every virtual chunk read fails.

(Split out from #24 as requested there.)

Where

translateToHttpUrl ([email protected]):

if (bucket.includes(".")) {
  return `https://s3.amazonaws.com/${bucket}/${key}`;   // path-style, global endpoint
}
return `https://${bucket}.s3.amazonaws.com/${key}`;       // virtual-hosted

Dotted bucket names can't use virtual-hosted style over TLS (cert mismatch), so the path-style branch is correct — but it hardcodes the global s3.amazonaws.com host, which 301s for non-us-east-1 buckets.

And in the virtual fetch (makeUrlStore / getRange):

if (response.status !== 200 && response.status !== 206) {
  throw new Error(`Failed to fetch virtual chunk from ${url}: ${response.status} ${response.statusText}`);
}

→ the 301 is thrown rather than followed.

Reproduction

Public store with virtual refs into a dotted, us-west-2 bucket (s3://us-west-2.opendata.source.coop/…):

https://data.source.coop/tge-labs/meta-chm-v2/zarr/chm.zarr.icechunk

import { HttpStorage, Repository, IcechunkStore } from "icechunk-js";
import * as zarr from "zarrita";

const url = "https://data.source.coop/tge-labs/meta-chm-v2/zarr/chm.zarr.icechunk";
const repo = await Repository.open({ storage: new HttpStorage(url) });
const session = await repo.checkoutBranch("main");
const ice = await IcechunkStore.open(session, { withRangeCoalescing: zarr.withRangeCoalescing });
const group = await zarr.open.v3(ice, { kind: "group" });
const a = await zarr.open.v3(group.resolve("64x/chm"), { kind: "array" });
await zarr.get(a, [zarr.slice(0, 512), zarr.slice(0, 512)]); // a populated region
// → Error: Failed to fetch virtual chunk from
//   https://s3.amazonaws.com/us-west-2.opendata.source.coop/.../chm/2101003131.tif: 301 Moved Permanently

Verified endpoint behavior for that object (range request bytes=0-100):

URL Result
https://s3.amazonaws.com/us-west-2.opendata.source.coop/… (what icechunk builds) 301 (x-amz-bucket-region: us-west-2)
https://s3.us-west-2.amazonaws.com/us-west-2.opendata.source.coop/… (regional path-style) 206 ✓
https://data.source.coop/… (public CORS proxy) 206 ✓

Suggested fixes (any one)

  1. Follow redirects on the virtual fetch — let fetch follow the 301 (default redirect: "follow") and accept the final 200/206, instead of throwing on the 301 status. Simplest and fixes the general case.
  2. Use the regional path-style endpoint for dotted buckets when the region is known — https://s3.<region>.amazonaws.com/<bucket>/<key>. Region could come from a virtual-chunk-container config / repo config option.
  3. Document the fetchClient hook as the supported workaround for custom endpoint/CORS routing (we use it to rewrite onto a CORS proxy).

Workaround in use

A custom fetchClient that rewrites the path-style URL onto a CORS-enabled host:

const ice = await IcechunkStore.open(session, {
  withRangeCoalescing: zarr.withRangeCoalescing,
  fetchClient: {
    fetch: (u, init) => fetch(
      u.replace(
        /^https:\/\/s3(?:[.-][a-z0-9-]+)?\.amazonaws\.com\/[a-z0-9-]+\.opendata\.source\.coop\//,
        "https://data.source.coop/",
      ),
      init,
    ),
  },
});

Activity

  1. tylere commented on Jun 24, 2026

    @tylere
    Author

    Verified fixed in 0.6.0 🎉 — regionalS3RedirectUrl now retries a 301/307 (with x-amz-bucket-region) against https://s3.<region>.amazonaws.com/<bucket>/<key>, and that regional endpoint serves the objects with Access-Control-Allow-Origin: *, so it works in the browser too. Reading the store without any custom fetchClient now succeeds. Thanks! Leaving open for a maintainer to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions