Skip to content

Commit ce04f8f

Browse files
committed
postinstall: add timeout when fetching
When fetching things during postinstall, add a much shorter timeout to ensure things keep progressing. If nodejs/node/issues/43187 gets resolved, we may be able to switch to importing `node:undici` instead of adding another copy with possibly incompatible API. Signed-off-by: Mark Yen <[email protected]>
1 parent 8b18041 commit ce04f8f

File tree

3 files changed

+21
-40
lines changed

3 files changed

+21
-40
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
"ts-node": "10.9.2",
169169
"tsconfig-paths": "4.2.0",
170170
"typescript": "5.5.4",
171+
"undici": "^6.19.8",
171172
"vue-eslint-parser": "9.4.3",
172173
"vue-jest": "3.0.7",
173174
"vue-template-compiler": "2.7.16",

scripts/lib/download.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import path from 'path';
1010
import stream from 'stream';
1111

1212
import { simpleSpawn } from 'scripts/simple_process';
13+
import { Agent, RetryAgent } from 'undici';
1314

1415
type ChecksumAlgorithm = 'sha1' | 'sha256' | 'sha512';
1516

@@ -30,18 +31,17 @@ export type ArchiveDownloadOptions = DownloadOptions & {
3031
};
3132

3233
async function fetchWithRetry(url: string) {
33-
while (true) {
34-
try {
35-
return await fetch(url, { redirect: 'follow' });
36-
} catch (ex: any) {
37-
if (ex && ex.errno === 'EAI_AGAIN') {
38-
console.log(`Recoverable error downloading ${ url }, retrying...`);
39-
continue;
40-
}
41-
console.dir(ex);
42-
throw ex;
43-
}
44-
}
34+
const agent = new RetryAgent(new Agent({ bodyTimeout: 1_000 }), {
35+
maxTimeout: 5_000,
36+
errorCodes: ['EAI_AGAIN', 'ECONNRESET', 'ECONNREFUSED', 'ENETDOWN',
37+
'ENETUNREACH', 'EHOSTDOWN', 'UND_ERR_SOCKET', 'UND_ERR_BODY_TIMEOUT'],
38+
retry: (err, context, cb) => {
39+
console.log(`Recoverable error ${ err } downloading ${ url }, retrying...`);
40+
cb(null);
41+
return null;
42+
},
43+
});
44+
return await fetch(url, { redirect: 'follow', dispatcher: agent } as any);
4545
}
4646

4747
/**

yarn.lock

+8-28
Original file line numberDiff line numberDiff line change
@@ -12259,16 +12259,7 @@ string-length@^5.0.1:
1225912259
char-regex "^2.0.0"
1226012260
strip-ansi "^7.0.1"
1226112261

12262-
"string-width-cjs@npm:string-width@^4.2.0":
12263-
version "4.2.3"
12264-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
12265-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
12266-
dependencies:
12267-
emoji-regex "^8.0.0"
12268-
is-fullwidth-code-point "^3.0.0"
12269-
strip-ansi "^6.0.1"
12270-
12271-
string-width@^2.1.1, string-width@^4, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3, string-width@^5.0.1, string-width@^5.1.2:
12262+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^2.1.1, string-width@^4, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3, string-width@^5.0.1, string-width@^5.1.2:
1227212263
version "4.2.3"
1227312264
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1227412265
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -12346,7 +12337,7 @@ string_decoder@~1.1.1:
1234612337
dependencies:
1234712338
safe-buffer "~5.1.0"
1234812339

12349-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
12340+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1235012341
version "6.0.1"
1235112342
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1235212343
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -12367,13 +12358,6 @@ strip-ansi@^4.0.0:
1236712358
dependencies:
1236812359
ansi-regex "^3.0.0"
1236912360

12370-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
12371-
version "6.0.1"
12372-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
12373-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
12374-
dependencies:
12375-
ansi-regex "^5.0.1"
12376-
1237712361
strip-ansi@^7.0.1:
1237812362
version "7.1.0"
1237912363
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -13026,6 +13010,11 @@ undici-types@~5.26.4:
1302613010
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
1302713011
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
1302813012

13013+
undici@^6.19.8:
13014+
version "6.19.8"
13015+
resolved "https://registry.yarnpkg.com/undici/-/undici-6.19.8.tgz#002d7c8a28f8cc3a44ff33c3d4be4d85e15d40e1"
13016+
integrity sha512-U8uCCl2x9TK3WANvmBavymRzxbfFYG+tAu+fgx3zxQy3qdagQqBLwJVrdyO1TBfUXvfKveMKJZhpvUYoOjM+4g==
13017+
1302913018
1303013019
version "4.2.0"
1303113020
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-4.2.0.tgz#7e21b0ef7d363d8d9af0fb929a5555f6ef97a3be"
@@ -13702,7 +13691,7 @@ word-wrap@~1.2.3:
1370213691
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"
1370313692
integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==
1370413693

13705-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
13694+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1370613695
version "7.0.0"
1370713696
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1370813697
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -13728,15 +13717,6 @@ wrap-ansi@^6.2.0:
1372813717
string-width "^4.1.0"
1372913718
strip-ansi "^6.0.0"
1373013719

13731-
wrap-ansi@^7.0.0:
13732-
version "7.0.0"
13733-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
13734-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
13735-
dependencies:
13736-
ansi-styles "^4.0.0"
13737-
string-width "^4.1.0"
13738-
strip-ansi "^6.0.0"
13739-
1374013720
wrap-ansi@^8.1.0:
1374113721
version "8.1.0"
1374213722
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)