mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
catch exceptions from req.cancel() (#1359)
* catch exceptions from req.cancel() * catch other instances of req.cancel * fix prev commit
This commit is contained in:
@@ -1415,7 +1415,11 @@ class CallSession extends Emitter {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (this.req && !this.dlg) {
|
if (this.req && !this.dlg) {
|
||||||
|
try {
|
||||||
this.req.cancel();
|
this.req.cancel();
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error({err}, 'CallSession:_lccCallStatus error cancelling request');
|
||||||
|
}
|
||||||
this._callReleased();
|
this._callReleased();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class TaskRestDial extends Task {
|
|||||||
this.timeout = this.data.timeout || 60;
|
this.timeout = this.data.timeout || 60;
|
||||||
this.sipRequestWithinDialogHook = this.data.sipRequestWithinDialogHook;
|
this.sipRequestWithinDialogHook = this.data.sipRequestWithinDialogHook;
|
||||||
this.referHook = this.data.referHook;
|
this.referHook = this.data.referHook;
|
||||||
|
this.recentCallStatus = 0;
|
||||||
|
|
||||||
this.on('connect', this._onConnect.bind(this));
|
this.on('connect', this._onConnect.bind(this));
|
||||||
this.on('callStatus', this._onCallStatus.bind(this));
|
this.on('callStatus', this._onCallStatus.bind(this));
|
||||||
@@ -57,7 +58,11 @@ class TaskRestDial extends Task {
|
|||||||
this._clearCallTimer();
|
this._clearCallTimer();
|
||||||
if (this.canCancel) {
|
if (this.canCancel) {
|
||||||
this.canCancel = false;
|
this.canCancel = false;
|
||||||
|
try {
|
||||||
cs?.req?.cancel();
|
cs?.req?.cancel();
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error({err}, 'TaskRestDial: error cancelling call');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.notifyTaskDone();
|
this.notifyTaskDone();
|
||||||
}
|
}
|
||||||
@@ -118,7 +123,8 @@ class TaskRestDial extends Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_onCallStatus(status) {
|
_onCallStatus(status) {
|
||||||
this.logger.debug(`CallStatus: ${status}`);
|
this.logger.debug(`RestDial CallStatus: ${status}`);
|
||||||
|
this.recentCallStatus = status;
|
||||||
if (status >= 200) {
|
if (status >= 200) {
|
||||||
this.canCancel = false;
|
this.canCancel = false;
|
||||||
this._clearCallTimer();
|
this._clearCallTimer();
|
||||||
@@ -136,11 +142,16 @@ class TaskRestDial extends Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_onCallTimeout() {
|
_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;
|
this.timer = null;
|
||||||
if (this.canCancel) {
|
if (this.canCancel && this.recentCallStatus < 200) {
|
||||||
|
this.logger.debug('TaskRestDial: cancelling call attempt');
|
||||||
this.canCancel = false;
|
this.canCancel = false;
|
||||||
|
try {
|
||||||
this.cs?.req?.cancel();
|
this.cs?.req?.cancel();
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error({err}, 'TaskRestDial: error cancelling call');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -329,7 +329,13 @@ class SingleDialer extends Emitter {
|
|||||||
*/
|
*/
|
||||||
async kill(Reason) {
|
async kill(Reason) {
|
||||||
this.killed = true;
|
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) {
|
else if (this.dlg && this.dlg.connected) {
|
||||||
const duration = moment().diff(this.dlg.connectTime, 'seconds');
|
const duration = moment().diff(this.dlg.connectTime, 'seconds');
|
||||||
this.logger.debug('SingleDialer:kill hanging up called party');
|
this.logger.debug('SingleDialer:kill hanging up called party');
|
||||||
|
|||||||
Reference in New Issue
Block a user