From 4b19391156683a57a8f1c96e9fba219282cfed04 Mon Sep 17 00:00:00 2001 From: Sergiy Kyrylkov Date: Wed, 27 Apr 2022 10:53:39 +0200 Subject: [PATCH 1/8] Set fetch timeout to 300 seconds --- lib/fetch/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index c4ec1faf5b3..f53912f73d8 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -1920,7 +1920,9 @@ async function httpNetworkFetch ( method: request.method, body: fetchParams.controller.dispatcher[kIsMockActive] ? request.body && request.body.source : body, headers: [...request.headersList].flat(), - maxRedirections: 0 + maxRedirections: 0, + bodyTimeout: 300e3, + headersTimeout: 300e3 }, { body: null, From 3f0cd690147888dad322f723b4d040d73927a016 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 27 Apr 2022 11:52:42 +0200 Subject: [PATCH 2/8] Update lib/fetch/index.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michaƫl Zasso --- lib/fetch/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index f53912f73d8..ec1503c159e 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -1921,8 +1921,8 @@ async function httpNetworkFetch ( body: fetchParams.controller.dispatcher[kIsMockActive] ? request.body && request.body.source : body, headers: [...request.headersList].flat(), maxRedirections: 0, - bodyTimeout: 300e3, - headersTimeout: 300e3 + bodyTimeout: 300_000, + headersTimeout: 300_000 }, { body: null, From 9abcd90d508063b51c20cc80d51eb18d44f476d4 Mon Sep 17 00:00:00 2001 From: Sergiy Kyrylkov Date: Wed, 27 Apr 2022 13:05:03 +0200 Subject: [PATCH 3/8] Add fetch timeout tests --- test/node-fetch/main.js | 17 +++++++++++++++++ test/node-fetch/utils/server.js | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/test/node-fetch/main.js b/test/node-fetch/main.js index 77a61a29454..aa14a638672 100644 --- a/test/node-fetch/main.js +++ b/test/node-fetch/main.js @@ -1641,4 +1641,21 @@ describe('node-fetch', () => { expect(res.ok).to.be.false }) }) + + it('should not time out waiting for a response 60 seconds', function () { + this.timeout(65_000); + return fetch(`${base}timeout60s`).then(res => { + expect(res.status).to.equal(200) + expect(res.ok).to.be.true + return res.text().then(result => { + expect(result).to.equal('text') + }) + }) + + }) + + it('should time out waiting for more than 300 seconds', function () { + this.timeout(305_000); + return expect(fetch(`${base}timeout300s`)).to.eventually.be.rejectedWith(TypeError) + }) }) diff --git a/test/node-fetch/utils/server.js b/test/node-fetch/utils/server.js index a2817a2d30b..867d995d487 100644 --- a/test/node-fetch/utils/server.js +++ b/test/node-fetch/utils/server.js @@ -13,7 +13,7 @@ module.exports = class TestServer { console.log(err.stack) }) this.server.on('connection', socket => { - socket.setTimeout(1500) + socket.setTimeout(310_000) }) } @@ -227,6 +227,22 @@ module.exports = class TestServer { }, 1000) } + if (p === '/timeout60s') { + setTimeout(() => { + res.statusCode = 200 + res.setHeader('Content-Type', 'text/plain') + res.end('text') + }, 60_000) + } + + if (p === '/timeout300s') { + setTimeout(() => { + res.statusCode = 200 + res.setHeader('Content-Type', 'text/plain') + res.end('text') + }, 300_000) + } + if (p === '/slow') { res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') From 524b34bb5d21c3fa95ebf5c7d06fb888cd5117c8 Mon Sep 17 00:00:00 2001 From: Sergiy Kyrylkov Date: Wed, 27 Apr 2022 13:07:52 +0200 Subject: [PATCH 4/8] Fix formatting --- test/node-fetch/main.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/node-fetch/main.js b/test/node-fetch/main.js index aa14a638672..e016a086b5c 100644 --- a/test/node-fetch/main.js +++ b/test/node-fetch/main.js @@ -1643,19 +1643,18 @@ describe('node-fetch', () => { }) it('should not time out waiting for a response 60 seconds', function () { - this.timeout(65_000); - return fetch(`${base}timeout60s`).then(res => { + this.timeout(65_000) + return fetch(`${base}timeout60s`).then(res => { expect(res.status).to.equal(200) expect(res.ok).to.be.true return res.text().then(result => { expect(result).to.equal('text') }) }) - }) it('should time out waiting for more than 300 seconds', function () { - this.timeout(305_000); + this.timeout(305_000) return expect(fetch(`${base}timeout300s`)).to.eventually.be.rejectedWith(TypeError) }) }) From 8aab7cb0e1df5e38151472fa7fdcde97df0c9b20 Mon Sep 17 00:00:00 2001 From: Sergiy Kyrylkov Date: Wed, 27 Apr 2022 13:47:46 +0200 Subject: [PATCH 5/8] Skip fetch timeout tests --- test/node-fetch/main.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/node-fetch/main.js b/test/node-fetch/main.js index e016a086b5c..6ff4cb890e0 100644 --- a/test/node-fetch/main.js +++ b/test/node-fetch/main.js @@ -1643,6 +1643,7 @@ describe('node-fetch', () => { }) it('should not time out waiting for a response 60 seconds', function () { + this.skip() this.timeout(65_000) return fetch(`${base}timeout60s`).then(res => { expect(res.status).to.equal(200) @@ -1654,6 +1655,7 @@ describe('node-fetch', () => { }) it('should time out waiting for more than 300 seconds', function () { + this.skip() this.timeout(305_000) return expect(fetch(`${base}timeout300s`)).to.eventually.be.rejectedWith(TypeError) }) From 0dd9a1b7354dcc950a168ef344cadee45fcbaa6f Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 27 Apr 2022 14:02:31 +0200 Subject: [PATCH 6/8] skip tests --- test/node-fetch/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/node-fetch/main.js b/test/node-fetch/main.js index 6ff4cb890e0..45781d421d7 100644 --- a/test/node-fetch/main.js +++ b/test/node-fetch/main.js @@ -1642,7 +1642,7 @@ describe('node-fetch', () => { }) }) - it('should not time out waiting for a response 60 seconds', function () { + xit('should not time out waiting for a response 60 seconds', function () { this.skip() this.timeout(65_000) return fetch(`${base}timeout60s`).then(res => { @@ -1654,7 +1654,7 @@ describe('node-fetch', () => { }) }) - it('should time out waiting for more than 300 seconds', function () { + xit('should time out waiting for more than 300 seconds', function () { this.skip() this.timeout(305_000) return expect(fetch(`${base}timeout300s`)).to.eventually.be.rejectedWith(TypeError) From 66f13657ef69a21b236cd484af04cbb0cc97b29c Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 27 Apr 2022 14:09:17 +0200 Subject: [PATCH 7/8] fixup --- test/node-fetch/main.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/test/node-fetch/main.js b/test/node-fetch/main.js index 45781d421d7..a6d1501f40d 100644 --- a/test/node-fetch/main.js +++ b/test/node-fetch/main.js @@ -1642,21 +1642,19 @@ describe('node-fetch', () => { }) }) - xit('should not time out waiting for a response 60 seconds', function () { - this.skip() - this.timeout(65_000) - return fetch(`${base}timeout60s`).then(res => { - expect(res.status).to.equal(200) - expect(res.ok).to.be.true - return res.text().then(result => { - expect(result).to.equal('text') - }) - }) - }) - - xit('should time out waiting for more than 300 seconds', function () { - this.skip() - this.timeout(305_000) - return expect(fetch(`${base}timeout300s`)).to.eventually.be.rejectedWith(TypeError) - }) + // it('should not time out waiting for a response 60 seconds', function () { + // this.timeout(65_000) + // return fetch(`${base}timeout60s`).then(res => { + // expect(res.status).to.equal(200) + // expect(res.ok).to.be.true + // return res.text().then(result => { + // expect(result).to.equal('text') + // }) + // }) + // }) + + // it('should time out waiting for more than 300 seconds', function () { + // this.timeout(305_000) + // return expect(fetch(`${base}timeout300s`)).to.eventually.be.rejectedWith(TypeError) + // }) }) From 6390e7df25469be5ea3af02151d3a1a77724d2e0 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 27 Apr 2022 14:11:16 +0200 Subject: [PATCH 8/8] fixup --- test/node-fetch/utils/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/node-fetch/utils/server.js b/test/node-fetch/utils/server.js index 867d995d487..97b551582bd 100644 --- a/test/node-fetch/utils/server.js +++ b/test/node-fetch/utils/server.js @@ -13,7 +13,7 @@ module.exports = class TestServer { console.log(err.stack) }) this.server.on('connection', socket => { - socket.setTimeout(310_000) + socket.setTimeout(1500) }) }