Worker to Worker request never completes.

I'm using a worker to send a fetch request to another with services binding, but it seems to never give a reply or something. The request does work when its not coming from the worker. I don't think there's any relevant code. There's no error at all, the request never finishes.
3 Replies
Walshy
Walshy•2w ago
Code?
Mike Keller
Mike KellerOP•2w ago
On 1 worker I'm using Next.js in Workers based of: https://developers.cloudflare.com/workers/frameworks/framework-guides/nextjs/ (Code is too big to send here) But for the fetch I'm using:
await (await getCloudflareContext()).env.API.fetch(Request);
//then
await response.json();
await (await getCloudflareContext()).env.API.fetch(Request);
//then
await response.json();
(Yes I added the binding) Small example of the one that receives it:
export default {
async fetch(request, env, ctx) {
await env.D1.prepare("INSERT INTO jobs (id) VALUES (?1)").bind("123").run();

ctx.waitUntil(
await env.QUEUE.send(
{
id: "123",
},
{ contentType: "json" }
)
);

return new Response(
JSON.stringify({
id: "123",
}),
{
status: 200,
headers: new Headers({
"Content-Type": "application/json",
}),
}
);
},
};
export default {
async fetch(request, env, ctx) {
await env.D1.prepare("INSERT INTO jobs (id) VALUES (?1)").bind("123").run();

ctx.waitUntil(
await env.QUEUE.send(
{
id: "123",
},
{ contentType: "json" }
)
);

return new Response(
JSON.stringify({
id: "123",
}),
{
status: 200,
headers: new Headers({
"Content-Type": "application/json",
}),
}
);
},
};
Cloudflare Docs
Next.js · Cloudflare Workers docs
Create an Next.js application and deploy it to Cloudflare Workers with Workers Assets.
Mike Keller
Mike KellerOP•11h ago
The request does seem to work as queue is sent and proccessed. But I never get a reply on the 1st worker. Uhm, any idea? 😭 :NotLikeThis: Please help... Bruh. HELPPPP

Did you find this page helpful?