From b9597e944377e74907607ee280ec1e8c31dd3156 Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Thu, 15 Jul 2021 14:27:49 -0400 Subject: [PATCH] make-fetch-happen@9.0.4 --- .../make-fetch-happen/lib/cache/entry.js | 30 ++++++++++++++++--- .../make-fetch-happen/lib/cache/policy.js | 2 +- node_modules/make-fetch-happen/lib/remote.js | 1 + node_modules/make-fetch-happen/package.json | 2 +- package-lock.json | 14 ++++----- package.json | 2 +- 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/node_modules/make-fetch-happen/lib/cache/entry.js b/node_modules/make-fetch-happen/lib/cache/entry.js index 41f8a3d215ee1..a2acea156ee6f 100644 --- a/node_modules/make-fetch-happen/lib/cache/entry.js +++ b/node_modules/make-fetch-happen/lib/cache/entry.js @@ -48,6 +48,7 @@ const KEEP_RESPONSE_HEADERS = [ // return an object containing all metadata to be written to the index const getMetadata = (request, response, options) => { const metadata = { + time: Date.now(), url: request.url, reqHeaders: {}, resHeaders: {}, @@ -112,9 +113,18 @@ const _policy = Symbol('policy') class CacheEntry { constructor ({ entry, request, response, options }) { - this.entry = entry + if (entry) { + this.key = entry.key + this.entry = entry + // previous versions of this module didn't write an explicit timestamp in + // the metadata, so fall back to the entry's timestamp. we can't use the + // entry timestamp to determine staleness because cacache will update it + // when it verifies its data + this.entry.metadata.time = this.entry.metadata.time || this.entry.time + } else + this.key = cacheKey(request) + this.options = options - this.key = entry ? entry.key : cacheKey(request) // these properties are behind getters that lazily evaluate this[_request] = request @@ -340,13 +350,25 @@ class CacheEntry { const content = await cacache.get.byDigest(this.options.cachePath, this.entry.integrity, { memoize: this.options.memoize }) body.end(content) } catch (err) { + if (err.code === 'EINTEGRITY') + await cacache.rm.content(this.options.cachePath, this.entry.integrity, { memoize: this.options.memoize }) + if (err.code === 'ENOENT' || err.code === 'EINTEGRITY') + await CacheEntry.invalidate(this.request, this.options) body.emit('error', err) } } } else { onResume = () => { const cacheStream = cacache.get.stream.byDigest(this.options.cachePath, this.entry.integrity, { memoize: this.options.memoize }) - cacheStream.on('error', (err) => body.emit('error', err)) + cacheStream.on('error', async (err) => { + cacheStream.pause() + if (err.code === 'EINTEGRITY') + await cacache.rm.content(this.options.cachePath, this.entry.integrity, { memoize: this.options.memoize }) + if (err.code === 'ENOENT' || err.code === 'EINTEGRITY') + await CacheEntry.invalidate(this.request, this.options) + body.emit('error', err) + cacheStream.resume() + }) cacheStream.pipe(body) } } @@ -368,7 +390,7 @@ class CacheEntry { response.headers.set('x-local-cache-key', encodeURIComponent(this.key)) response.headers.set('x-local-cache-mode', shouldBuffer ? 'buffer' : 'stream') response.headers.set('x-local-cache-status', status) - response.headers.set('x-local-cache-time', new Date(this.entry.time).toUTCString()) + response.headers.set('x-local-cache-time', new Date(this.entry.metadata.time).toUTCString()) return response } diff --git a/node_modules/make-fetch-happen/lib/cache/policy.js b/node_modules/make-fetch-happen/lib/cache/policy.js index 189dce80ee68e..e0959f64ddf9d 100644 --- a/node_modules/make-fetch-happen/lib/cache/policy.js +++ b/node_modules/make-fetch-happen/lib/cache/policy.js @@ -67,7 +67,7 @@ class CachePolicy { // this is necessary because the CacheSemantics constructor forces // the value to Date.now() which means a policy created from a // cache entry is likely to always identify itself as stale - this.policy._responseTime = this.entry.time + this.policy._responseTime = this.entry.metadata.time } } diff --git a/node_modules/make-fetch-happen/lib/remote.js b/node_modules/make-fetch-happen/lib/remote.js index e37f39de845f3..7e4ed24edb530 100644 --- a/node_modules/make-fetch-happen/lib/remote.js +++ b/node_modules/make-fetch-happen/lib/remote.js @@ -14,6 +14,7 @@ const RETRY_ERRORS = [ 'ECONNREFUSED', // remote host refused to open connection 'EADDRINUSE', // failed to bind to a local port (proxy?) 'ETIMEDOUT', // someone in the transaction is WAY TOO SLOW + 'ERR_SOCKET_TIMEOUT', // same as above, but this one comes from agentkeepalive // Known codes we do NOT retry on: // ENOTFOUND (getaddrinfo failure. Either bad hostname, or offline) ] diff --git a/node_modules/make-fetch-happen/package.json b/node_modules/make-fetch-happen/package.json index 44330998bb02f..e4a26a9cd94df 100644 --- a/node_modules/make-fetch-happen/package.json +++ b/node_modules/make-fetch-happen/package.json @@ -1,6 +1,6 @@ { "name": "make-fetch-happen", - "version": "9.0.3", + "version": "9.0.4", "description": "Opinionated, caching, retrying fetch client", "main": "lib/index.js", "files": [ diff --git a/package-lock.json b/package-lock.json index fa82aeddbf3c1..674aab5415f38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -118,7 +118,7 @@ "libnpmsearch": "^3.1.1", "libnpmteam": "^2.0.3", "libnpmversion": "^1.2.1", - "make-fetch-happen": "^9.0.3", + "make-fetch-happen": "^9.0.4", "minipass": "^3.1.3", "minipass-pipeline": "^1.2.4", "mkdirp": "^1.0.4", @@ -4968,9 +4968,9 @@ } }, "node_modules/make-fetch-happen": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.0.3.tgz", - "integrity": "sha512-uZ/9Cf2vKqsSWZyXhZ9wHHyckBrkntgbnqV68Bfe8zZenlf7D6yuGMXvHZQ+jSnzPkjosuNP1HGasj1J4h8OlQ==", + "version": "9.0.4", + "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.0.4.tgz", + "integrity": "sha512-sQWNKMYqSmbAGXqJg2jZ+PmHh5JAybvwu0xM8mZR/bsTjGiTASj3ldXJV7KFHy1k/IJIBkjxQFoWIVsv9+PQMg==", "inBundle": true, "dependencies": { "agentkeepalive": "^4.1.3", @@ -14016,9 +14016,9 @@ } }, "make-fetch-happen": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.0.3.tgz", - "integrity": "sha512-uZ/9Cf2vKqsSWZyXhZ9wHHyckBrkntgbnqV68Bfe8zZenlf7D6yuGMXvHZQ+jSnzPkjosuNP1HGasj1J4h8OlQ==", + "version": "9.0.4", + "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.0.4.tgz", + "integrity": "sha512-sQWNKMYqSmbAGXqJg2jZ+PmHh5JAybvwu0xM8mZR/bsTjGiTASj3ldXJV7KFHy1k/IJIBkjxQFoWIVsv9+PQMg==", "requires": { "agentkeepalive": "^4.1.3", "cacache": "^15.2.0", diff --git a/package.json b/package.json index 76645816adb15..fd77e92bf217c 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "libnpmsearch": "^3.1.1", "libnpmteam": "^2.0.3", "libnpmversion": "^1.2.1", - "make-fetch-happen": "^9.0.3", + "make-fetch-happen": "^9.0.4", "minipass": "^3.1.3", "minipass-pipeline": "^1.2.4", "mkdirp": "^1.0.4",