Skip to content
This repository was archived by the owner on Aug 23, 2019. It is now read-only.

Commit a7e2ae2

Browse files
committed
fix: prevent undefined error during a mutual hangup
1 parent 4b60484 commit a7e2ae2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/dial.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ class Dialer {
212212
}
213213

214214
const muxedConn = this.switch.muxers[key].dialer(conn)
215-
this.switch.muxedConns[b58Id] = {}
216-
this.switch.muxedConns[b58Id].muxer = muxedConn
215+
this.switch.muxedConns[b58Id] = {
216+
muxer: muxedConn
217+
}
217218

218219
muxedConn.once('close', () => {
219220
delete this.switch.muxedConns[b58Id]

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ class Switch extends EE {
110110
this.stats.stop()
111111
series([
112112
(cb) => each(this.muxedConns, (conn, cb) => {
113+
// If the connection was destroyed while we are hanging up, continue
114+
if (conn === undefined) {
115+
return cb()
116+
}
117+
113118
conn.muxer.end((err) => {
114119
// If OK things are fine, and someone just shut down
115120
if (err && err.message !== 'Fatal error: OK') {

0 commit comments

Comments
 (0)