From ef3ac6a8a056bcacb3adc9ca737e26245853ae5b Mon Sep 17 00:00:00 2001 From: Fawaz Ahmed Date: Tue, 25 Jun 2024 17:57:36 +0530 Subject: [PATCH 01/10] fix: don't override user defined MaxListeners Fixes https://github.com/nodejs/node/issues/47449 --- lib/web/fetch/request.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/web/fetch/request.js b/lib/web/fetch/request.js index bc436aa9705..dde0d8aacd0 100644 --- a/lib/web/fetch/request.js +++ b/lib/web/fetch/request.js @@ -429,8 +429,6 @@ class Request { // This is only available in node >= v19.9.0 if (typeof getMaxListeners === 'function' && getMaxListeners(signal) === defaultMaxListeners) { setMaxListeners(1500, signal) - } else if (getEventListeners(signal, 'abort').length >= defaultMaxListeners) { - setMaxListeners(1500, signal) } } catch {} From cd602c6ae130033203af6fc98e9b0c712df92472 Mon Sep 17 00:00:00 2001 From: Fawaz Ahmed Date: Wed, 26 Jun 2024 02:55:51 +0530 Subject: [PATCH 02/10] lint fix --- lib/web/fetch/request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web/fetch/request.js b/lib/web/fetch/request.js index dde0d8aacd0..51bb2b3ab14 100644 --- a/lib/web/fetch/request.js +++ b/lib/web/fetch/request.js @@ -28,7 +28,7 @@ const { webidl } = require('./webidl') const { URLSerializer } = require('./data-url') const { kConstruct } = require('../../core/symbols') const assert = require('node:assert') -const { getMaxListeners, setMaxListeners, getEventListeners, defaultMaxListeners } = require('node:events') +const { getMaxListeners, setMaxListeners, defaultMaxListeners } = require('node:events') const kAbortController = Symbol('abortController') From 1efb435cebbd9ede216942280b7553aa0a7499e5 Mon Sep 17 00:00:00 2001 From: Fawaz Ahmed Date: Wed, 26 Jun 2024 02:59:29 +0530 Subject: [PATCH 03/10] add test --- test/fetch/max-listeners.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/fetch/max-listeners.js diff --git a/test/fetch/max-listeners.js b/test/fetch/max-listeners.js new file mode 100644 index 00000000000..e62a9275e32 --- /dev/null +++ b/test/fetch/max-listeners.js @@ -0,0 +1,13 @@ +const { setMaxListeners, getMaxListeners } = require('events') +const { test } = require('node:test') +const assert = require('node:assert') +const { fetch } = require('../..') + +test('test max listeners', async (t) => { + const controller = new AbortController(); + setMaxListeners(Infinity, controller.signal) + let url = URL.createObjectURL(new Blob()) + for(let i=0;i<1600;i++) + fetch(url, { signal: controller.signal }) + assert.strictEqual(getMaxListeners(controller.signal), Infinity); +}); \ No newline at end of file From 273212c97b9b509ebbdda6b7edad2763c9346722 Mon Sep 17 00:00:00 2001 From: Fawaz Ahmed Date: Wed, 26 Jun 2024 04:43:13 +0530 Subject: [PATCH 04/10] Update test/fetch/max-listeners.js Co-authored-by: tsctx <91457664+tsctx@users.noreply.github.com> --- test/fetch/max-listeners.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/fetch/max-listeners.js b/test/fetch/max-listeners.js index e62a9275e32..1ea7fd10754 100644 --- a/test/fetch/max-listeners.js +++ b/test/fetch/max-listeners.js @@ -1,4 +1,6 @@ -const { setMaxListeners, getMaxListeners } = require('events') +'use strict' + +const { setMaxListeners, getMaxListeners, defaultMaxListeners } = require('events') const { test } = require('node:test') const assert = require('node:assert') const { fetch } = require('../..') From a2eef4ea66f9a3f1d7af780087b580193139985f Mon Sep 17 00:00:00 2001 From: Fawaz Ahmed Date: Wed, 26 Jun 2024 04:45:41 +0530 Subject: [PATCH 05/10] use defaultMaxListeners --- test/fetch/max-listeners.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fetch/max-listeners.js b/test/fetch/max-listeners.js index 1ea7fd10754..50a1dc38eba 100644 --- a/test/fetch/max-listeners.js +++ b/test/fetch/max-listeners.js @@ -9,7 +9,7 @@ test('test max listeners', async (t) => { const controller = new AbortController(); setMaxListeners(Infinity, controller.signal) let url = URL.createObjectURL(new Blob()) - for(let i=0;i<1600;i++) + for(let i=0;i<=defaultMaxListeners;i++) fetch(url, { signal: controller.signal }) assert.strictEqual(getMaxListeners(controller.signal), Infinity); }); \ No newline at end of file From 2d59cdcf97f931e6c1395336e18b1bbc5b0cfc3a Mon Sep 17 00:00:00 2001 From: Fawaz Ahmed Date: Wed, 26 Jun 2024 05:04:09 +0530 Subject: [PATCH 06/10] Update test/fetch/max-listeners.js Co-authored-by: tsctx <91457664+tsctx@users.noreply.github.com> --- test/fetch/max-listeners.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fetch/max-listeners.js b/test/fetch/max-listeners.js index 50a1dc38eba..bbfb81ed975 100644 --- a/test/fetch/max-listeners.js +++ b/test/fetch/max-listeners.js @@ -3,7 +3,7 @@ const { setMaxListeners, getMaxListeners, defaultMaxListeners } = require('events') const { test } = require('node:test') const assert = require('node:assert') -const { fetch } = require('../..') +const { Request } = require('../..') test('test max listeners', async (t) => { const controller = new AbortController(); From 164ff349a8a680039c74d11f709bb2b77b3a4b36 Mon Sep 17 00:00:00 2001 From: Fawaz Ahmed Date: Wed, 26 Jun 2024 05:06:09 +0530 Subject: [PATCH 07/10] commit suggestions --- test/fetch/max-listeners.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/fetch/max-listeners.js b/test/fetch/max-listeners.js index bbfb81ed975..84ea2ec122f 100644 --- a/test/fetch/max-listeners.js +++ b/test/fetch/max-listeners.js @@ -8,8 +8,7 @@ const { Request } = require('../..') test('test max listeners', async (t) => { const controller = new AbortController(); setMaxListeners(Infinity, controller.signal) - let url = URL.createObjectURL(new Blob()) for(let i=0;i<=defaultMaxListeners;i++) - fetch(url, { signal: controller.signal }) + new Request('http://asd', { signal: controller.signal }) assert.strictEqual(getMaxListeners(controller.signal), Infinity); }); \ No newline at end of file From 7b23dd3dcaf86228c723c81db534d9afdaed8242 Mon Sep 17 00:00:00 2001 From: Fawaz Ahmed Date: Wed, 26 Jun 2024 09:38:08 +0530 Subject: [PATCH 08/10] remove unused async keyword --- test/fetch/max-listeners.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fetch/max-listeners.js b/test/fetch/max-listeners.js index 84ea2ec122f..a9e3307474a 100644 --- a/test/fetch/max-listeners.js +++ b/test/fetch/max-listeners.js @@ -5,7 +5,7 @@ const { test } = require('node:test') const assert = require('node:assert') const { Request } = require('../..') -test('test max listeners', async (t) => { +test('test max listeners', (t) => { const controller = new AbortController(); setMaxListeners(Infinity, controller.signal) for(let i=0;i<=defaultMaxListeners;i++) From e3752131416d4ef2618d107cc274df0e48351449 Mon Sep 17 00:00:00 2001 From: Fawaz Ahmed Date: Wed, 26 Jun 2024 10:29:05 +0530 Subject: [PATCH 09/10] npm run lint:fix --- test/fetch/max-listeners.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/fetch/max-listeners.js b/test/fetch/max-listeners.js index a9e3307474a..3266d0645c4 100644 --- a/test/fetch/max-listeners.js +++ b/test/fetch/max-listeners.js @@ -6,9 +6,8 @@ const assert = require('node:assert') const { Request } = require('../..') test('test max listeners', (t) => { - const controller = new AbortController(); - setMaxListeners(Infinity, controller.signal) - for(let i=0;i<=defaultMaxListeners;i++) - new Request('http://asd', { signal: controller.signal }) - assert.strictEqual(getMaxListeners(controller.signal), Infinity); -}); \ No newline at end of file + const controller = new AbortController() + setMaxListeners(Infinity, controller.signal) + for (let i = 0; i <= defaultMaxListeners; i++) { new Request('http://asd', { signal: controller.signal }) } + assert.strictEqual(getMaxListeners(controller.signal), Infinity) +}) From 7a9237c3090c2cef1ad6e15ed0f9ef04e7a9871a Mon Sep 17 00:00:00 2001 From: Fawaz Ahmed Date: Wed, 26 Jun 2024 18:24:07 +0530 Subject: [PATCH 10/10] Update test/fetch/max-listeners.js Co-authored-by: tsctx <91457664+tsctx@users.noreply.github.com> --- test/fetch/max-listeners.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/fetch/max-listeners.js b/test/fetch/max-listeners.js index 3266d0645c4..36e4fef101b 100644 --- a/test/fetch/max-listeners.js +++ b/test/fetch/max-listeners.js @@ -8,6 +8,9 @@ const { Request } = require('../..') test('test max listeners', (t) => { const controller = new AbortController() setMaxListeners(Infinity, controller.signal) - for (let i = 0; i <= defaultMaxListeners; i++) { new Request('http://asd', { signal: controller.signal }) } + for (let i = 0; i <= defaultMaxListeners; i++) { + // eslint-disable-next-line no-new + new Request('http://asd', { signal: controller.signal }) + } assert.strictEqual(getMaxListeners(controller.signal), Infinity) })