Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wrangler] fix: fix local Durable Object proxies not working #5669

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/odd-guests-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"wrangler": patch
---

fix: fix broken Durable Object local proxying (when no `cf` property is present)

A regression was introduced in wrangler 3.46.0 (https://github.com/cloudflare/workers-sdk/pull/5215)
which made it so that missing `Request#cf` properties are serialized as `"undefined"`, this in turn
throws a syntax parse error when such values are parsed via `JSON.parse` breaking the communication
with Durable Object local proxies. Fix such issue by serializing missing `Request#cf` properties as
`"{}"` instead.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe("getPlatformProxy - bindings", () => {
await dispose();
});

it.skip("correctly obtains functioning DO bindings (provided by external local workers)", async () => {
it("correctly obtains functioning DO bindings (provided by external local workers)", async () => {
const { env, dispose } = await getPlatformProxy<Env>({
configPath: wranglerTomlFilePath,
});
Expand Down
12 changes: 6 additions & 6 deletions packages/wrangler/src/dev/miniflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ function createProxyPrototypeClass(handlerSuperKlass, getUnknownPrototypeKey) {
return getUnknownPrototypeKey(key);
}
});
return Reflect.construct(handlerSuperKlass, [ctx, env], klass);
}
Reflect.setPrototypeOf(klass.prototype, handlerSuperKlass.prototype);
Reflect.setPrototypeOf(klass, handlerSuperKlass);
Expand All @@ -111,7 +111,7 @@ function createDurableObjectClass({ className, proxyUrl }) {
const klass = createProxyPrototypeClass(DurableObject, (key) => {
throw new Error(\`Cannot access \\\`\${className}#\${key}\\\` as Durable Object RPC is not yet supported between multiple \\\`wrangler dev\\\` sessions.\`);
});
// Forward regular HTTP requests to the other "wrangler dev" session
klass.prototype.fetch = function(request) {
if (proxyUrl === undefined) {
Expand All @@ -121,7 +121,7 @@ function createDurableObjectClass({ className, proxyUrl }) {
proxyRequest.headers.set(HEADER_URL, request.url);
proxyRequest.headers.set(HEADER_NAME, className);
proxyRequest.headers.set(HEADER_ID, this.ctx.id.toString());
proxyRequest.headers.set(HEADER_CF_BLOB, JSON.stringify(request.cf));
proxyRequest.headers.set(HEADER_CF_BLOB, JSON.stringify(request.cf ?? {}));
return fetch(proxyRequest);
};
Expand All @@ -147,7 +147,7 @@ export default {
const originalUrl = request.headers.get(HEADER_URL);
const className = request.headers.get(HEADER_NAME);
const idString = request.headers.get(HEADER_ID);
const cfBlobString = request.headers.get(HEADER_CF_BLOB);
const cf = JSON.parse(request.headers.get(HEADER_CF_BLOB));
if (originalUrl === null || className === null || idString === null) {
return new Response("[wrangler] Received Durable Object proxy request with missing headers", { status: 400 });
}
Expand All @@ -159,7 +159,7 @@ export default {
const ns = env[className];
const id = ns.idFromString(idString);
const stub = ns.get(id);
return stub.fetch(request, { cf: JSON.parse(cfBlobString ?? "{}") });
return stub.fetch(request, { cf });
}
}
`;
Expand Down
Loading