Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ async function download (gyp, url) {
Connection: 'keep-alive'
},
proxy: gyp.opts.proxy,
noProxy: gyp.opts.noproxy
noProxy: gyp.opts.noproxy,
retry: 3
}

const cafile = gyp.opts.cafile
Expand Down
26 changes: 26 additions & 0 deletions test/test-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,32 @@ describe('download', function () {
assert.notStrictEqual(cas[0], cas[1])
})

it('download will retry on ECONNRESET', async function () {
let requestCount = 0
const server = http.createServer((req, res) => {
requestCount++
if (requestCount < 3) {
req.socket.destroy()
return
}
res.end('ok')
})

after(() => new Promise((resolve) => server.close(resolve)))

const host = 'localhost'
await new Promise((resolve) => server.listen(0, host, resolve))
const { port } = server.address()
const gyp = {
opts: {},
version: '42'
}
const url = `http://${host}:${port}`
const res = await download(gyp, url)
assert.strictEqual(await res.text(), 'ok')
assert.ok(requestCount >= 2, `expected at least 2 requests but got ${requestCount}`)
})

// only run this test if we are running a version of Node with predictable version path behavior

it('download headers (actual)', async function () {
Expand Down
Loading