From de2c601632bac41cc8b85b2d3a122f4ed24a7aed Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 31 Dec 2021 08:41:57 +0100 Subject: [PATCH] fix: catch errors from setMaxListeners (#275) Fails in electron-renderer --- src/query-self.js | 4 +++- src/query/manager.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/query-self.js b/src/query-self.js index 27621954..f5170021 100644 --- a/src/query-self.js +++ b/src/query-self.js @@ -71,7 +71,9 @@ class QuerySelf extends EventEmitter { this._controller = new AbortController() const signal = anySignal([this._controller.signal, timeoutController.signal]) // this controller will get used for lots of dial attempts so make sure we don't cause warnings to be logged - setMaxListeners && setMaxListeners(Infinity, signal) + try { + setMaxListeners && setMaxListeners(Infinity, signal) + } catch {} // fails on node < 15.4 const found = await length(await take(this._peerRouting.getClosestPeers(this._peerId.toBytes(), { signal }), this._count)) diff --git a/src/query/manager.js b/src/query/manager.js index 1ed4bc9f..e3b617f1 100644 --- a/src/query/manager.js +++ b/src/query/manager.js @@ -104,7 +104,7 @@ class QueryManager { // so make sure we don't make a lot of noise in the logs try { setMaxListeners && setMaxListeners(0, signal) - } catch {} // fails on node < 15 + } catch {} // fails on node < 15.4 const log = logger(`libp2p:kad-dht:${this._lan ? 'lan' : 'wan'}:query:` + uint8ArrayToString(key, 'base58btc'))