|
1 | 1 | import { NextFunction, Request, Response } from "express"; |
| 2 | +import { Agent, fetch } from "undici"; |
2 | 3 | import { config } from "../../config"; |
3 | 4 | import { logger } from "../../lib/logger"; |
4 | 5 | import { RequestWithMaybeACUC } from "../v1/types"; |
5 | 6 |
|
6 | | -const TIMEOUT_MS = 65_000; |
| 7 | +const TIMEOUT_MS = 120_000; |
7 | 8 |
|
8 | 9 | const FORWARDED_REQUEST_HEADERS = ["content-type", "accept", "x-request-id"]; |
9 | 10 | const FORWARDED_RESPONSE_HEADERS = ["content-type", "x-request-id"]; |
10 | 11 |
|
| 12 | +const dispatcher = new Agent({ |
| 13 | + connectTimeout: TIMEOUT_MS, |
| 14 | + headersTimeout: TIMEOUT_MS, |
| 15 | + bodyTimeout: TIMEOUT_MS, |
| 16 | +}); |
| 17 | + |
11 | 18 | export function researchFlagMiddleware( |
12 | 19 | req: RequestWithMaybeACUC<any, any, any>, |
13 | 20 | res: Response, |
@@ -45,10 +52,11 @@ export async function researchProxyController( |
45 | 52 | if (typeof v === "string") headers[h] = v; |
46 | 53 | } |
47 | 54 |
|
48 | | - const init: RequestInit = { |
| 55 | + const init: Parameters<typeof fetch>[1] = { |
49 | 56 | method: req.method, |
50 | 57 | headers, |
51 | 58 | signal: AbortSignal.timeout(TIMEOUT_MS), |
| 59 | + dispatcher, |
52 | 60 | }; |
53 | 61 |
|
54 | 62 | if (req.method !== "GET" && req.method !== "HEAD") { |
|
0 commit comments