From eeec8c309982f7eea839c02190c80dcbd5a9b26d Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Sat, 13 Apr 2024 21:16:35 +0700 Subject: [PATCH] gather is hang if listenDuringPrompt = false and say/play task throw exception (#717) --- lib/tasks/gather.js | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 1c106836..e9adb65c 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -187,12 +187,7 @@ class TaskGather extends SttTask { try { if (this.sayTask) { const {span, ctx} = this.startChildSpan(`nested:${this.sayTask.summary}`); - this.sayTask.span = span; - this.sayTask.ctx = ctx; - this.sayTask.exec(cs, {ep}); // kicked off, _not_ waiting for it to complete - this.sayTask.on('playDone', (err) => { - span.end(); - if (err) this.logger.error({err}, 'Gather:exec Error playing tts'); + const process = () => { this.logger.debug('Gather: nested say task completed'); if (!this.killed) { startListening(cs, ep); @@ -203,16 +198,22 @@ class TaskGather extends SttTask { }); } } + }; + this.sayTask.span = span; + this.sayTask.ctx = ctx; + this.sayTask.exec(cs, {ep}) // kicked off, _not_ waiting for it to complete + .catch((err) => { + process(); + }); + this.sayTask.on('playDone', (err) => { + span.end(); + if (err) this.logger.error({err}, 'Gather:exec Error playing tts'); + process(); }); } else if (this.playTask) { const {span, ctx} = this.startChildSpan(`nested:${this.playTask.summary}`); - this.playTask.span = span; - this.playTask.ctx = ctx; - this.playTask.exec(cs, {ep}); // kicked off, _not_ waiting for it to complete - this.playTask.on('playDone', (err) => { - span.end(); - if (err) this.logger.error({err}, 'Gather:exec Error playing url'); + const process = () => { this.logger.debug('Gather: nested play task completed'); if (!this.killed) { startListening(cs, ep); @@ -223,6 +224,17 @@ class TaskGather extends SttTask { }); } } + }; + this.playTask.span = span; + this.playTask.ctx = ctx; + this.playTask.exec(cs, {ep}) // kicked off, _not_ waiting for it to complete + .catch((err) => { + process(); + }); + this.playTask.on('playDone', (err) => { + span.end(); + if (err) this.logger.error({err}, 'Gather:exec Error playing url'); + process(); }); } else {