From 950f1c83b7adadc344492fee6c84abd230fe4748 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Thu, 1 Oct 2020 12:46:58 -0400 Subject: [PATCH] bugfix for race condition where incoming call canceled quickly leading to potential endless loop --- lib/session/call-session.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 6ddfbfb7..d8c0d392 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -8,6 +8,7 @@ const makeTask = require('../tasks/make_task'); const normalizeJambones = require('../utils/normalize-jambones'); const listTaskNames = require('../utils/summarize-tasks'); 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. @@ -497,8 +498,15 @@ class CallSession extends Emitter { return ep; } catch (err) { - this.logger.error(err, `Error attempting to allocate endpoint for for task ${task.name}`); - throw new Error(`${BADPRECONDITIONS}: unable to allocate endpoint`); + if (err === CALLER_CANCELLED_ERR_MSG) { + 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`); + } } }