From 5e3bd91f8cfca38b076f403b16cabdbd63499cd6 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Wed, 4 Jan 2023 09:24:39 -0500 Subject: [PATCH] Bugfix/gather kill race condition (#207) * further fix for race condition in #206 * #206: ignore request to start bot mode when bot mode is already active --- lib/session/call-session.js | 4 ++-- lib/tasks/gather.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 44d6cc63..5c608709 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -450,8 +450,8 @@ class CallSession extends Emitter { async enableBotMode(gather, autoEnable) { try { if (this.backgroundGatherTask) { - this.logger.info('CallSession:enableBotMode - bot mode currently enabled, stop it'); - this.disableBotMode(); + this.logger.info('CallSession:enableBotMode - bot mode currently enabled, ignoring request to start again'); + return; } const t = normalizeJambones(this.logger, [gather]); this.backgroundGatherTask = makeTask(this.logger, t[0]); diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 5b2430a8..5687e5ed 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -191,6 +191,10 @@ class TaskGather extends Task { if (this.input.includes('speech') && !this.listenDuringPrompt) { this._initSpeech(cs, ep) .then(() => { + if (this.killed) { + this.logger.info('Gather:exec - task was quickly killed so do not transcribe'); + return; + } this._startTranscribing(ep); return updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid); }) @@ -223,7 +227,13 @@ class TaskGather extends Task { if (!this.killed) startListening(cs, ep); }); } - else startListening(cs, ep); + else { + if (this.killed) { + this.logger.info('Gather:exec - task was immediately killed so do not transcribe'); + return; + } + startListening(cs, ep); + } if (this.input.includes('speech') && this.listenDuringPrompt) { await this._initSpeech(cs, ep);