destroy http requests after timeout

Massimo Melina committed May 14, 2026 at 11:03 UTC 99ad8e2096e42378868f6262e392c1aaf0af71af
2 files changed +4 -1
src/selfCheck.ts
+2 -1
@@ -48,7 +48,8 @@ export async function selfCheck(url: string) {
48 console.debug(svc)
49 body = applySymbols(body)
50 serviceUrl = applySymbols(serviceUrl)!
51 - const res = await haveTimeout(8_000, httpString(serviceUrl, { family, ...rest, body }))
51 + const timeout = 8_000
52 + const res = await haveTimeout(timeout, httpString(serviceUrl, { family, timeout, ...rest, body }))
53 const success = new RegExp(regexpSuccess).test(res)
54 const failure = new RegExp(regexpFailure).test(res)
55 if (success === failure) throw 'inconsistent: ' + service + ': ' + res // this result cannot be trusted
src/util-http.ts
+2
@@ -110,6 +110,8 @@ export function httpStream(url: string, { body, proxy, jar, noRedirect, httpThro
110 e.cause ??= req // enrich the error
111 reject(e)
112 })
113 + if (options.timeout) // node only emits the timeout event, so destroy the request to unblock callers waiting for the body
114 + req.setTimeout(options.timeout, () => req.destroy(Object.assign(Error('timeout'), { code: 'ETIMEDOUT' })))
115 if (body && body instanceof Readable)
116 body.pipe(req).on('end', () => req.end())
117 else