fix gather race condition (#759)

This commit is contained in:
Dave Horton
2024-05-22 14:03:15 -04:00
committed by GitHub
parent 6be3fd9b64
commit d132bdb92b
2 changed files with 9 additions and 4 deletions

View File

@@ -79,6 +79,7 @@ class InboundCallSession extends CallSession {
this.logger.info('InboundCallSession:_hangup - race condition, dlg cleared by app hangup'); this.logger.info('InboundCallSession:_hangup - race condition, dlg cleared by app hangup');
return; return;
} }
this.logger.info(`InboundCallSession: ${terminatedBy} hung up`);
assert(this.dlg.connectTime); assert(this.dlg.connectTime);
const duration = moment().diff(this.dlg.connectTime, 'seconds'); const duration = moment().diff(this.dlg.connectTime, 'seconds');
this.rootSpan.setAttributes({'call.termination': `hangup by ${terminatedBy}`}); this.rootSpan.setAttributes({'call.termination': `hangup by ${terminatedBy}`});
@@ -87,7 +88,6 @@ class InboundCallSession extends CallSession {
callStatus: CallStatus.Completed, callStatus: CallStatus.Completed,
duration duration
}); });
this.logger.info(`InboundCallSession: ${terminatedBy} hung up`);
this._callReleased(); this._callReleased();
this.req.removeAllListeners('cancel'); this.req.removeAllListeners('cancel');
} }

View File

@@ -259,10 +259,15 @@ class TaskGather extends SttTask {
if (this.input.includes('speech') && this.listenDuringPrompt) { if (this.input.includes('speech') && this.listenDuringPrompt) {
await this._setSpeechHandlers(cs, ep); await this._setSpeechHandlers(cs, ep);
if (!this.resolved && !this.killed) {
this._startTranscribing(ep); this._startTranscribing(ep);
updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid) updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid)
.catch(() => {/*already logged error */}); .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) { if (this.input.includes('digits') || this.dtmfBargein || this.asrDtmfTerminationDigit) {
ep.on('dtmf', this._onDtmf.bind(this, cs, ep)); ep.on('dtmf', this._onDtmf.bind(this, cs, ep));