From 38a0e69ed81df7edac4d8b90c7e9924ad47f55ae Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Sun, 8 Sep 2024 12:24:39 +0200 Subject: [PATCH] fix: extract noop everywhere (#3559) (cherry picked from commit 7f0f6c97e0d8fbe7cf2053ec4f6608a9bc65c956) --- lib/dispatcher/client.js | 6 ++++-- lib/dispatcher/proxy-agent.js | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/dispatcher/client.js b/lib/dispatcher/client.js index 7e22aa000ba..3dc356618ba 100644 --- a/lib/dispatcher/client.js +++ b/lib/dispatcher/client.js @@ -63,6 +63,8 @@ let deprecatedInterceptorWarned = false const kClosedResolve = Symbol('kClosedResolve') +const noop = () => {} + function getPipelining (client) { return client[kPipelining] ?? client[kHTTPContext]?.defaultPipelining ?? 1 } @@ -442,7 +444,7 @@ async function connect (client) { }) if (client.destroyed) { - util.destroy(socket.on('error', () => {}), new ClientDestroyedError()) + util.destroy(socket.on('error', noop), new ClientDestroyedError()) return } @@ -453,7 +455,7 @@ async function connect (client) { ? await connectH2(client, socket) : await connectH1(client, socket) } catch (err) { - socket.destroy().on('error', () => {}) + socket.destroy().on('error', noop) throw err } diff --git a/lib/dispatcher/proxy-agent.js b/lib/dispatcher/proxy-agent.js index 226b67846da..c439d7cd555 100644 --- a/lib/dispatcher/proxy-agent.js +++ b/lib/dispatcher/proxy-agent.js @@ -23,6 +23,8 @@ function defaultFactory (origin, opts) { return new Pool(origin, opts) } +const noop = () => {} + class ProxyAgent extends DispatcherBase { constructor (opts) { super() @@ -81,7 +83,7 @@ class ProxyAgent extends DispatcherBase { servername: this[kProxyTls]?.servername || proxyHostname }) if (statusCode !== 200) { - socket.on('error', () => {}).destroy() + socket.on('error', noop).destroy() callback(new RequestAbortedError(`Proxy response (${statusCode}) !== 200 when HTTP Tunneling`)) } if (opts.protocol !== 'https:') {