Skip to content

Commit

Permalink
improv: fix reconnection with axon #58
Browse files Browse the repository at this point in the history
  • Loading branch information
Eywek committed May 31, 2018
1 parent 52ec505 commit 5f3dfd8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/transporters/AxonTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,22 @@ module.exports = class AxonTransport extends Transporter {
})

// Errors / close
this._socket.on('close', this._onClose.bind(this))
this._socket.on('error', this._onError.bind(this))
this._axon.sock.on('close', this._onClose.bind(this))
this._axon.sock.on('error', this._onError.bind(this))
this._socket.on('close', _ => {
log('Got a close on nssocket connection')
this._onClose()
})
this._socket.on('error', (err) => {
log(`Got an error on nssocket connection: ${err.message}`)
this._onError()
})
this._axon.sock.on('close', _ => {
log('Got a close on axon connection')
this._onClose()
})
this._axon.sock.on('error', (err) => {
log(`Got an error on axon connection: ${err.message}`)
this._onError()
})

// Setup listener
this._socket.data('*', function (data) {
Expand Down Expand Up @@ -121,6 +133,8 @@ module.exports = class AxonTransport extends Transporter {
const isNsSocketConnected = this._socket && this._socket.connected
const isAxonConnected = this._axon && this._axon.sock.connected && this._axon.sock.socks &&
this._axon.sock.socks[0] && this._axon.sock.socks[0].bufferSize < 290000
if (!isNsSocketConnected) log('Nssocket is not connected anymore')
if (!isAxonConnected) log('Axon is not connected anymore')
return isNsSocketConnected && isAxonConnected
}

Expand Down
1 change: 1 addition & 0 deletions src/transporters/Transporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module.exports = class Transporter extends EventEmitter2 {

// re-send all of the data
while (this.queue.length > 0) {
if (!this.isConnected()) return
let packet = this.queue[0]
this.send(packet.channel, packet.data)
this.queue.shift()
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1112,8 +1112,8 @@ pm2-axon-rpc@^0.5.0:
debug "^3.0"

pm2-axon@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/pm2-axon/-/pm2-axon-3.2.0.tgz#570262c1607f22a1d42b080a725029f977d6cdc3"
version "3.3.0"
resolved "https://registry.yarnpkg.com/pm2-axon/-/pm2-axon-3.3.0.tgz#a9badfdb8e083fbd5d7d24317b4a21eb708f0735"
dependencies:
amp "~0.3.1"
amp-message "~0.1.1"
Expand Down

0 comments on commit 5f3dfd8

Please sign in to comment.