From 6fb4ec8b50129deac6bef65a12d3ee0a0fb09339 Mon Sep 17 00:00:00 2001 From: Khafra <42794878+KhafraDev@users.noreply.github.com> Date: Wed, 26 Oct 2022 12:44:26 -0400 Subject: [PATCH] fix(fetch): remove terminated event listener on redirect (#1715) * fix(fetch): remove terminated event listener on redirect * fix: use setMaxListeners instead * Update lib/fetch/index.js Co-authored-by: Robert Nagy --- lib/fetch/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index 4bb0173551e..6fcd106039e 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -74,6 +74,12 @@ class Fetch extends EE { this.connection = null this.dump = false this.state = 'ongoing' + // 2 terminated listeners get added per request, + // but only 1 gets removed. If there are 20 redirects, + // 21 listeners will be added. + // See https://github.com/nodejs/undici/issues/1711 + // TODO (fix): Find and fix root cause for leaked listener. + this.setMaxListeners(21) } terminate (reason) {