diff --git a/lib/utils/place-outdial.js b/lib/utils/place-outdial.js index b7786217..7e6017e0 100644 --- a/lib/utils/place-outdial.js +++ b/lib/utils/place-outdial.js @@ -181,6 +181,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');