From a3e9fab86f9d8c24906eeebca201e40ef63a68df 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 46aa401..bb3e139 100644 --- a/src/dial.js +++ b/src/dial.js @@ -267,8 +267,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..1b096bd 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) { + return cb() + } + conn.muxer.end((err) => { // If OK things are fine, and someone just shut down if (err && err.message !== 'Fatal error: OK') {