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

fix: prevent undefined error during a mutual hangup #260

Merged
merged 1 commit into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/dial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down