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

Commit

Permalink
fix: prevent undefined error during a mutual hangup
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun committed May 29, 2018
1 parent 4b60484 commit a7e2ae2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/dial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
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 === undefined) {
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

0 comments on commit a7e2ae2

Please sign in to comment.