gatsby-source-filesystem 2.1.46 → 2.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.1.48](https://github.com/gatsbyjs/gatsby/compare/gatsby-source-filesystem@2.1.47...gatsby-source-filesystem@2.1.48) (2020-02-01)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **gatsby-source-filesystem:** Retry stalled remote file downloads ([#20843](https://github.com/gatsbyjs/gatsby/issues/20843)) ([536686b](https://github.com/gatsbyjs/gatsby/commit/536686b))
11
+
12
+ ## [2.1.47](https://github.com/gatsbyjs/gatsby/compare/gatsby-source-filesystem@2.1.46...gatsby-source-filesystem@2.1.47) (2020-01-29)
13
+
14
+ **Note:** Version bump only for package gatsby-source-filesystem
15
+
6
16
  ## [2.1.46](https://github.com/gatsbyjs/gatsby/compare/gatsby-source-filesystem@2.1.45...gatsby-source-filesystem@2.1.46) (2020-01-09)
7
17
 
8
18
  **Note:** Version bump only for package gatsby-source-filesystem
@@ -80,6 +80,10 @@ let totalJobs = 0;
80
80
 
81
81
  const CACHE_DIR = `.cache`;
82
82
  const FS_PLUGIN_DIR = `gatsby-source-filesystem`;
83
+ const STALL_RETRY_LIMIT = 3;
84
+ const STALL_TIMEOUT = 30000;
85
+ const CONNECTION_RETRY_LIMIT = 5;
86
+ const CONNECTION_TIMEOUT = 30000;
83
87
  /********************
84
88
  * Queue Management *
85
89
  ********************/
@@ -142,31 +146,64 @@ async function pushToQueue(task, cb) {
142
146
  * @param {Headers} headers
143
147
  * @param {String} tmpFilename
144
148
  * @param {Object} httpOpts
149
+ * @param {number} attempt
145
150
  * @return {Promise<Object>} Resolves with the [http Result Object]{@link https://nodejs.org/api/http.html#http_class_http_serverresponse}
146
151
  */
147
152
 
148
153
 
149
- const requestRemoteNode = (url, headers, tmpFilename, httpOpts) => new Promise((resolve, reject) => {
150
- const opts = Object.assign({}, {
151
- timeout: 30000,
152
- retries: 5
153
- }, httpOpts);
154
+ const requestRemoteNode = (url, headers, tmpFilename, httpOpts, attempt = 1) => new Promise((resolve, reject) => {
155
+ let timeout; // Called if we stall for 30s without receiving any data
156
+
157
+ const handleTimeout = async () => {
158
+ fsWriteStream.close();
159
+ fs.removeSync(tmpFilename);
160
+
161
+ if (attempt < STALL_RETRY_LIMIT) {
162
+ // Retry by calling ourself recursively
163
+ resolve(requestRemoteNode(url, headers, tmpFilename, httpOpts, attempt + 1));
164
+ } else {
165
+ reject(`Failed to download ${url} after ${STALL_RETRY_LIMIT} attempts`);
166
+ }
167
+ };
168
+
169
+ const resetTimeout = () => {
170
+ if (timeout) {
171
+ clearTimeout(timeout);
172
+ }
173
+
174
+ timeout = setTimeout(handleTimeout, STALL_TIMEOUT);
175
+ };
176
+
154
177
  const responseStream = got.stream(url, Object.assign({
155
- headers
156
- }, opts));
178
+ headers,
179
+ timeout: CONNECTION_TIMEOUT,
180
+ retries: CONNECTION_RETRY_LIMIT
181
+ }, httpOpts));
157
182
  const fsWriteStream = fs.createWriteStream(tmpFilename);
158
- responseStream.pipe(fsWriteStream);
159
- responseStream.on(`downloadProgress`, pro => console.log(pro)); // If there's a 400/500 response or other error.
183
+ responseStream.pipe(fsWriteStream); // If there's a 400/500 response or other error.
184
+
185
+ responseStream.on(`error`, error => {
186
+ if (timeout) {
187
+ clearTimeout(timeout);
188
+ }
160
189
 
161
- responseStream.on(`error`, (error, body, response) => {
162
190
  fs.removeSync(tmpFilename);
163
191
  reject(error);
164
192
  });
165
193
  fsWriteStream.on(`error`, error => {
194
+ if (timeout) {
195
+ clearTimeout(timeout);
196
+ }
197
+
166
198
  reject(error);
167
199
  });
168
200
  responseStream.on(`response`, response => {
201
+ resetTimeout();
169
202
  fsWriteStream.on(`finish`, () => {
203
+ if (timeout) {
204
+ clearTimeout(timeout);
205
+ }
206
+
170
207
  resolve(response);
171
208
  });
172
209
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gatsby-source-filesystem",
3
3
  "description": "Gatsby plugin which parses files within a directory for further parsing by other plugins",
4
- "version": "2.1.46",
4
+ "version": "2.1.48",
5
5
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
6
6
  "bugs": {
7
7
  "url": "https://github.com/gatsbyjs/gatsby/issues"
@@ -13,8 +13,8 @@
13
13
  "chokidar": "3.3.0",
14
14
  "file-type": "^12.4.0",
15
15
  "fs-extra": "^8.1.0",
16
- "gatsby-core-utils": "^1.0.26",
17
- "got": "^7.1.0",
16
+ "gatsby-core-utils": "^1.0.28",
17
+ "got": "^8.3.2",
18
18
  "md5-file": "^3.2.3",
19
19
  "mime": "^2.4.4",
20
20
  "pretty-bytes": "^5.3.0",
@@ -26,7 +26,7 @@
26
26
  "devDependencies": {
27
27
  "@babel/cli": "^7.7.5",
28
28
  "@babel/core": "^7.7.5",
29
- "babel-preset-gatsby-package": "^0.2.15",
29
+ "babel-preset-gatsby-package": "^0.2.16",
30
30
  "cross-env": "^5.2.1"
31
31
  },
32
32
  "homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-filesystem#readme",
@@ -52,5 +52,5 @@
52
52
  "engines": {
53
53
  "node": ">=8.0.0"
54
54
  },
55
- "gitHead": "4b6e778f75f531dba4f7dbe6c0af7daec1deac2a"
55
+ "gitHead": "b349d1096e65f2f3738e7230184d288264b03341"
56
56
  }