diff --git a/lib/utils/place-outdial.js b/lib/utils/place-outdial.js index 806e0637..b2818003 100644 --- a/lib/utils/place-outdial.js +++ b/lib/utils/place-outdial.js @@ -186,6 +186,15 @@ class SingleDialer extends Emitter { this.logger.debug(`SingleDialer:exec call connected: ${this.callSid}`); const connectTime = this.dlg.connectTime = moment(); + /* race condition: we were killed just as call was answered */ + if (this.killed) { + this.logger.info(`SingleDialer:exec race condition - we were killed as call connected: ${this.callSid}`); + const duration = moment().diff(connectTime, 'seconds'); + this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration}); + if (this.ep) this.ep.destroy(); + return; + } + this.dlg .on('destroy', () => { const duration = moment().diff(connectTime, 'seconds');