diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 9eec09a6..d4f61861 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -1415,7 +1415,11 @@ class CallSession extends Emitter { } else { if (this.req && !this.dlg) { - this.req.cancel(); + try { + this.req.cancel(); + } catch (err) { + this.logger.error({err}, 'CallSession:_lccCallStatus error cancelling request'); + } this._callReleased(); } } diff --git a/lib/tasks/rest_dial.js b/lib/tasks/rest_dial.js index 3db0b100..218e867d 100644 --- a/lib/tasks/rest_dial.js +++ b/lib/tasks/rest_dial.js @@ -19,6 +19,7 @@ class TaskRestDial extends Task { this.timeout = this.data.timeout || 60; this.sipRequestWithinDialogHook = this.data.sipRequestWithinDialogHook; this.referHook = this.data.referHook; + this.recentCallStatus = 0; this.on('connect', this._onConnect.bind(this)); this.on('callStatus', this._onCallStatus.bind(this)); @@ -57,7 +58,11 @@ class TaskRestDial extends Task { this._clearCallTimer(); if (this.canCancel) { this.canCancel = false; - cs?.req?.cancel(); + try { + cs?.req?.cancel(); + } catch (err) { + this.logger.error({err}, 'TaskRestDial: error cancelling call'); + } } this.notifyTaskDone(); } @@ -118,7 +123,8 @@ class TaskRestDial extends Task { } _onCallStatus(status) { - this.logger.debug(`CallStatus: ${status}`); + this.logger.debug(`RestDial CallStatus: ${status}`); + this.recentCallStatus = status; if (status >= 200) { this.canCancel = false; this._clearCallTimer(); @@ -136,11 +142,16 @@ class TaskRestDial extends Task { } _onCallTimeout() { - this.logger.debug('TaskRestDial: timeout expired without answer, killing task'); + this.logger.debug(`TaskRestDial: timeout expired without answer, last status ${this.recentCallStatus}`); this.timer = null; - if (this.canCancel) { + if (this.canCancel && this.recentCallStatus < 200) { + this.logger.debug('TaskRestDial: cancelling call attempt'); this.canCancel = false; - this.cs?.req?.cancel(); + try { + this.cs?.req?.cancel(); + } catch (err) { + this.logger.error({err}, 'TaskRestDial: error cancelling call'); + } } } diff --git a/lib/utils/place-outdial.js b/lib/utils/place-outdial.js index cfb95a96..d64c9e22 100644 --- a/lib/utils/place-outdial.js +++ b/lib/utils/place-outdial.js @@ -329,7 +329,13 @@ class SingleDialer extends Emitter { */ async kill(Reason) { this.killed = true; - if (this.inviteInProgress) await this.inviteInProgress.cancel(); + if (this.inviteInProgress) { + try { + await this.inviteInProgress.cancel(); + } catch (err) { + this.logger.error({err}, 'SingleDialer:kill error cancelling invite'); + } + } else if (this.dlg && this.dlg.connected) { const duration = moment().diff(this.dlg.connectTime, 'seconds'); this.logger.debug('SingleDialer:kill hanging up called party');