denoland / deploy_feedback

For reporting issues with Deno Deploy
https://deno.com/deploy
74 stars 5 forks source link

508: Loop Detected (LOOP_DETECTED) Recursive requests to the same deployment cannot be processed. #575

Open lordanubi opened 10 months ago

lordanubi commented 10 months ago

Hello I'm having some problems when deploying a script that locally was working perfectly. Since I needed some Vercel AI utiliities to deal with OpenAI streaming API which only works on Node.js, I had to set up an external worker on cloudflare that takes care of the streaming. This is my workflow:

Deno api endpoint /generate

if (pathname === "/generate") {
    //call to node server
    const call = await fetch("https://generate.jeieufbe43.workers.dev/", {
      method: "POST",
      body: JSON.stringify(request),
    });
    //proxy response body back to client for streaming
    return new Response(call.body, { status: 200 });
}

The cloudflare worker will make the request to OpenAI, stream the response back to Deno and finally it needs to save the generation on Deno database so it will send a fetch request to a Deno api endpoint /saveposts)


if (pathname === "/saveposts" && _req.method === "POST") {
    try {
      const res = JSON.parse(await _req.json()); // Parse JSON body
      const articles = res.news;
      for (const article of articles) {
        const articleKey = ["articles", ulid()];
        // Set the article with its unique key
        await kv.set(articleKey, article);
      }
      return new Response(JSON.stringify(articles), {
        status: 200,
      });
    } catch (error) {
      console.log("error", error);
      return new Response(error, { status: 500 });
    }
  }

Now for some reasons this request to deno server fails with this error: 508: Loop Detected (LOOP_DETECTED) Recursive requests to the same deployment cannot be processed.

Why is this perceived as a loop while it isn't? Shouldn't this error be triggered with at least 2 or 3 more callbacks?

lordanubi commented 10 months ago

Seems like I creating another Deno project connected to my first KV database is the only way to circumvent the problem

lordanubi commented 10 months ago

No luck even by doing this :(

Screenshot 2024-01-04 at 12 37 02

I even tried to directly connect to my db in nodejs but I get this error on my cloudflare worker

Screenshot 2024-01-04 at 12 39 51

Any idea on how could i prevent this? Can you change how the loop is detected in deno deploy please? That would help a lot!