Skip to content

Commit d812868

Browse files
committed
fix stuck orch if exception thrown and caught within orch
1 parent 70f4370 commit d812868

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

packages/durabletask-js/src/worker/runtime-orchestration-context.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,22 @@ export class RuntimeOrchestrationContext extends OrchestrationContext {
113113
if (this._previousTask.isFailed) {
114114
// Raise the failure as an exception to the generator. The orchestrator can then either
115115
// handle the exception or allow it to fail the orchestration.
116-
await this._generator.throw(this._previousTask._exception);
116+
const throwResult = await this._generator.throw(this._previousTask._exception);
117+
118+
// If the generator caught the exception and completed, signal completion
119+
if (throwResult.done) {
120+
throw new StopIterationError(throwResult.value);
121+
}
122+
123+
// If the generator yielded a new task after catching the exception
124+
if (throwResult.value instanceof Task) {
125+
this._previousTask = throwResult.value;
126+
// If the new task is already complete, continue processing
127+
if (this._previousTask.isComplete) {
128+
await this.resume();
129+
}
130+
return;
131+
}
117132
} else if (this._previousTask.isComplete) {
118133
while (true) {
119134
// Resume the generator. This will either return a Task or raise StopIteration if it's done.

0 commit comments

Comments
 (0)