Skip to content

Commit 1cb9537

Browse files
committed
fix(api): increase timeout
1 parent 1d6ae3e commit 1cb9537

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

apps/api/src/controllers/v2/research-proxy.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import { NextFunction, Request, Response } from "express";
2+
import { Agent, fetch } from "undici";
23
import { config } from "../../config";
34
import { logger } from "../../lib/logger";
45
import { RequestWithMaybeACUC } from "../v1/types";
56

6-
const TIMEOUT_MS = 65_000;
7+
const TIMEOUT_MS = 120_000;
78

89
const FORWARDED_REQUEST_HEADERS = ["content-type", "accept", "x-request-id"];
910
const FORWARDED_RESPONSE_HEADERS = ["content-type", "x-request-id"];
1011

12+
const dispatcher = new Agent({
13+
connectTimeout: TIMEOUT_MS,
14+
headersTimeout: TIMEOUT_MS,
15+
bodyTimeout: TIMEOUT_MS,
16+
});
17+
1118
export function researchFlagMiddleware(
1219
req: RequestWithMaybeACUC<any, any, any>,
1320
res: Response,
@@ -45,10 +52,11 @@ export async function researchProxyController(
4552
if (typeof v === "string") headers[h] = v;
4653
}
4754

48-
const init: RequestInit = {
55+
const init: Parameters<typeof fetch>[1] = {
4956
method: req.method,
5057
headers,
5158
signal: AbortSignal.timeout(TIMEOUT_MS),
59+
dispatcher,
5260
};
5361

5462
if (req.method !== "GET" && req.method !== "HEAD") {

0 commit comments

Comments
 (0)