Skip to content

Commit ff0d21c

Browse files
committed
chore: retry downloads on retryable errors
Assisted-by: Claude Opus 4.6
1 parent 19da158 commit ff0d21c

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/download.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ async function download (gyp, url) {
1111
Connection: 'keep-alive'
1212
},
1313
proxy: gyp.opts.proxy,
14-
noProxy: gyp.opts.noproxy
14+
noProxy: gyp.opts.noproxy,
15+
retry: 3
1516
}
1617

1718
const cafile = gyp.opts.cafile

test/test-download.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,32 @@ describe('download', function () {
153153
assert.notStrictEqual(cas[0], cas[1])
154154
})
155155

156+
it('download will retry on ECONNRESET', async function () {
157+
let requestCount = 0
158+
const server = http.createServer((req, res) => {
159+
requestCount++
160+
if (requestCount < 3) {
161+
req.socket.destroy()
162+
return
163+
}
164+
res.end('ok')
165+
})
166+
167+
after(() => new Promise((resolve) => server.close(resolve)))
168+
169+
const host = 'localhost'
170+
await new Promise((resolve) => server.listen(0, host, resolve))
171+
const { port } = server.address()
172+
const gyp = {
173+
opts: {},
174+
version: '42'
175+
}
176+
const url = `http://${host}:${port}`
177+
const res = await download(gyp, url)
178+
assert.strictEqual(await res.text(), 'ok')
179+
assert.ok(requestCount >= 2, `expected at least 2 requests but got ${requestCount}`)
180+
})
181+
156182
// only run this test if we are running a version of Node with predictable version path behavior
157183

158184
it('download headers (actual)', async function () {

0 commit comments

Comments
 (0)