Bun / Elysia 入口点无限循环

问题描述 投票:0回答:1

我用 Elysia 1.1.19 和 Bun 1.1.27 编写了这个应用程序:

const app = new Elysia()
.use(bearer())
.use(cors())
.use(
  staticPlugin({
    assets: "static",
    prefix: "/static",
  }),
);

const isProcessing = false;

app.get("/test-long-request", async () => {
  const timeToWait = 20000;
  const startTime = DateTime.now();

  if (isProcessing) {
    // If we enter again in the entrypoint before the end of the process (20 sec)
    console.error("Report generation is already in progress");
  }
  isProcessing = true;

  // We wait for 20 seconds
  await new Promise((r) => setTimeout(r, timeToWait));
  isProcessing = false;

  // We send response
  return new Response(
    `[${startTime.toMillis()}] - Ok after ${timeToWait / 1000} seconds`,
    { status: 200 },
  );
});

我使用这 3 个插件(Bearer、CORS 和 StaticPlugin)来执行应该替换超时的实际流程。我只是提及它们以防其他人遇到同样的问题。 DateTime 对象来自 luxon lib。

我的问题是,当我使用入口点(http://localhost:3000/test-long-request)验证 URL 时,入口点会在进程完成之前再次执行(具体来说,20 秒超时) 。这会导致无限循环,因为该过程永远不会完成并且响应永远不会发送。

超时超过10秒时会出现该问题。我不确定问题是否出在我的浏览器(Chrome v129.0.6668.101)重新执行请求或 Elysia 的问题。

还有其他人遇到过类似的问题吗?

bun elysiajs
1个回答
0
投票

Elysia 在内部使用

Bun.serve
,bun 在内部使用 uWS,其默认超时为 10 秒,如问题中所述 https://github.com/oven-sh/bun/issues/13392

您可以像

idleTimeout
一样传递
.listen({idleTimeout: 30})
选项,但您可能需要升级bun版本才能使用它们。

© www.soinside.com 2019 - 2024. All rights reserved.