bugfix for race condition where incoming call canceled quickly leading to potential endless loop

This commit is contained in:
Dave Horton
2020-10-01 12:46:58 -04:00
parent e642e13946
commit 950f1c83b7

View File

@@ -8,6 +8,7 @@ const makeTask = require('../tasks/make_task');
const normalizeJambones = require('../utils/normalize-jambones'); const normalizeJambones = require('../utils/normalize-jambones');
const listTaskNames = require('../utils/summarize-tasks'); const listTaskNames = require('../utils/summarize-tasks');
const BADPRECONDITIONS = 'preconditions not met'; const BADPRECONDITIONS = 'preconditions not met';
const CALLER_CANCELLED_ERR_MSG = 'Response not sent due to unknown transaction';
/** /**
* @classdesc Represents the execution context for a call. * @classdesc Represents the execution context for a call.
@@ -497,8 +498,15 @@ class CallSession extends Emitter {
return ep; return ep;
} catch (err) { } catch (err) {
this.logger.error(err, `Error attempting to allocate endpoint for for task ${task.name}`); if (err === CALLER_CANCELLED_ERR_MSG) {
throw new Error(`${BADPRECONDITIONS}: unable to allocate endpoint`); this.logger.error(err, 'caller canceled quickly before we could respond, ending call');
this._notifyCallStatusChange({callStatus: CallStatus.NoAnswer, sipStatus: 487});
this._callReleased();
}
else {
this.logger.error(err, `Error attempting to allocate endpoint for for task ${task.name}`);
throw new Error(`${BADPRECONDITIONS}: unable to allocate endpoint`);
}
} }
} }