Skip to content

Commit

Permalink
fix: forward connectionError
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jul 19, 2021
1 parent 4b5ed0b commit 5172fd9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const kDestroyed = Symbol('destroyed')
const kClosed = Symbol('closed')
const kOnConnect = Symbol('onConnect')
const kOnDisconnect = Symbol('onDisconnect')
const kOnConnectionError = Symbol('onConnectionError')
const kMaxRedirections = Symbol('maxRedirections')
const kOnDrain = Symbol('onDrain')
const kFactory = Symbol('factory')
Expand Down Expand Up @@ -75,6 +76,10 @@ class Agent extends Dispatcher {
this[kOnDisconnect] = (origin, targets, err) => {
agent.emit('disconnect', origin, [agent, ...targets], err)
}

this[kOnConnectionError] = (origin, targets, err) => {
agent.emit('connectionError', origin, [agent, ...targets], err)
}
}

get [kRunning] () {
Expand Down Expand Up @@ -116,9 +121,10 @@ class Agent extends Dispatcher {
let dispatcher = ref ? ref.deref() : null
if (!dispatcher) {
dispatcher = this[kFactory](opts.origin, this[kOptions])
.on('drain', this[kOnDrain])
.on('connect', this[kOnConnect])
.on('disconnect', this[kOnDisconnect])
.on('drain', this[kOnDrain])
.on('connectionError', this[kOnConnectionError])

this[kClients].set(opts.origin, new WeakRef(dispatcher))
this[kFinalizer].register(dispatcher, opts.origin)
Expand Down
6 changes: 6 additions & 0 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const kOptions = Symbol('options')
const kOnDrain = Symbol('onDrain')
const kOnConnect = Symbol('onConnect')
const kOnDisconnect = Symbol('onDisconnect')
const kOnConnectionError = Symbol('onConnectionError')
const kConnections = Symbol('connections')
const kFactory = Symbol('factory')
const kQueued = Symbol('queued')
Expand Down Expand Up @@ -102,6 +103,10 @@ class Pool extends Dispatcher {
this[kOnDisconnect] = (origin, targets, err) => {
pool.emit('disconnect', origin, [pool, ...targets], err)
}

this[kOnConnectionError] = (origin, targets, err) => {
pool.emit('connectionError', origin, [pool, ...targets], err)
}
}

get [kBusy] () {
Expand Down Expand Up @@ -162,6 +167,7 @@ class Pool extends Dispatcher {
.on('drain', this[kOnDrain])
.on('connect', this[kOnConnect])
.on('disconnect', this[kOnDisconnect])
.on('connectionError', this[kOnConnectionError])
this[kClients].push(dispatcher)
}
}
Expand Down

0 comments on commit 5172fd9

Please sign in to comment.