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
This commit is contained in:
Dave Horton
2023-01-04 09:24:39 -05:00
committed by GitHub
parent 050297825b
commit 5e3bd91f8c
2 changed files with 13 additions and 3 deletions

View File

@@ -450,8 +450,8 @@ class CallSession extends Emitter {
async enableBotMode(gather, autoEnable) { async enableBotMode(gather, autoEnable) {
try { try {
if (this.backgroundGatherTask) { if (this.backgroundGatherTask) {
this.logger.info('CallSession:enableBotMode - bot mode currently enabled, stop it'); this.logger.info('CallSession:enableBotMode - bot mode currently enabled, ignoring request to start again');
this.disableBotMode(); return;
} }
const t = normalizeJambones(this.logger, [gather]); const t = normalizeJambones(this.logger, [gather]);
this.backgroundGatherTask = makeTask(this.logger, t[0]); this.backgroundGatherTask = makeTask(this.logger, t[0]);

View File

@@ -191,6 +191,10 @@ class TaskGather extends Task {
if (this.input.includes('speech') && !this.listenDuringPrompt) { if (this.input.includes('speech') && !this.listenDuringPrompt) {
this._initSpeech(cs, ep) this._initSpeech(cs, ep)
.then(() => { .then(() => {
if (this.killed) {
this.logger.info('Gather:exec - task was quickly killed so do not transcribe');
return;
}
this._startTranscribing(ep); this._startTranscribing(ep);
return updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid); return updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid);
}) })
@@ -223,7 +227,13 @@ class TaskGather extends Task {
if (!this.killed) startListening(cs, ep); 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) { if (this.input.includes('speech') && this.listenDuringPrompt) {
await this._initSpeech(cs, ep); await this._initSpeech(cs, ep);