From a7e2ae23d79c4630cf990a638bee6c58e1005beb Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Tue, 29 May 2018 20:29:44 +0200 Subject: [PATCH] fix: prevent undefined error during a mutual hangup --- src/dial.js | 5 +++-- src/index.js | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dial.js b/src/dial.js index 450265c..00070ca 100644 --- a/src/dial.js +++ b/src/dial.js @@ -212,8 +212,9 @@ class Dialer { } const muxedConn = this.switch.muxers[key].dialer(conn) - this.switch.muxedConns[b58Id] = {} - this.switch.muxedConns[b58Id].muxer = muxedConn + this.switch.muxedConns[b58Id] = { + muxer: muxedConn + } muxedConn.once('close', () => { delete this.switch.muxedConns[b58Id] diff --git a/src/index.js b/src/index.js index 0ccea35..825d97b 100644 --- a/src/index.js +++ b/src/index.js @@ -110,6 +110,11 @@ class Switch extends EE { this.stats.stop() series([ (cb) => each(this.muxedConns, (conn, cb) => { + // If the connection was destroyed while we are hanging up, continue + if (conn === undefined) { + return cb() + } + conn.muxer.end((err) => { // If OK things are fine, and someone just shut down if (err && err.message !== 'Fatal error: OK') {