From d132bdb92b74b15aaa68e53df32c09b7c7253d0b Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Wed, 22 May 2024 14:03:15 -0400 Subject: [PATCH] fix gather race condition (#759) --- lib/session/inbound-call-session.js | 2 +- lib/tasks/gather.js | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/session/inbound-call-session.js b/lib/session/inbound-call-session.js index 5deb3882..20e6fcd6 100644 --- a/lib/session/inbound-call-session.js +++ b/lib/session/inbound-call-session.js @@ -79,6 +79,7 @@ class InboundCallSession extends CallSession { this.logger.info('InboundCallSession:_hangup - race condition, dlg cleared by app hangup'); return; } + this.logger.info(`InboundCallSession: ${terminatedBy} hung up`); assert(this.dlg.connectTime); const duration = moment().diff(this.dlg.connectTime, 'seconds'); this.rootSpan.setAttributes({'call.termination': `hangup by ${terminatedBy}`}); @@ -87,7 +88,6 @@ class InboundCallSession extends CallSession { callStatus: CallStatus.Completed, duration }); - this.logger.info(`InboundCallSession: ${terminatedBy} hung up`); this._callReleased(); this.req.removeAllListeners('cancel'); } diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index c072f603..3964b0a1 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -259,9 +259,14 @@ class TaskGather extends SttTask { if (this.input.includes('speech') && this.listenDuringPrompt) { await this._setSpeechHandlers(cs, ep); - this._startTranscribing(ep); - updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid) - .catch(() => {/*already logged error */}); + if (!this.resolved && !this.killed) { + this._startTranscribing(ep); + updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid) + .catch(() => {/*already logged error */}); + } + else { + this.logger.info('Gather:exec - task was killed or resolved quickly, not starting transcription'); + } } if (this.input.includes('digits') || this.dtmfBargein || this.asrDtmfTerminationDigit) {