Skip to content

Commit 4b42f77

Browse files
authored
fix: release concurrency token exhaustion no longer happens on batchTriggerAndWait (#1937)
1 parent 2aacf76 commit 4b42f77

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

internal-packages/run-engine/src/engine/systems/waitpointSystem.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ export class WaitpointSystem {
430430

431431
// Let the worker know immediately, so it can suspend the run
432432
await sendNotificationToWorker({ runId, snapshot, eventBus: this.$.eventBus });
433+
434+
if (isRunBlocked) {
435+
//release concurrency
436+
await this.releaseConcurrencySystem.releaseConcurrencyForSnapshot(snapshot);
437+
}
433438
}
434439

435440
if (timeout) {
@@ -448,10 +453,7 @@ export class WaitpointSystem {
448453

449454
//no pending waitpoint, schedule unblocking the run
450455
//debounce if we're rapidly adding waitpoints
451-
if (isRunBlocked) {
452-
//release concurrency
453-
await this.releaseConcurrencySystem.releaseConcurrencyForSnapshot(snapshot);
454-
} else {
456+
if (!isRunBlocked) {
455457
await this.$.worker.enqueue({
456458
//this will debounce the call
457459
id: `continueRunIfUnblocked:${runId}`,

references/hello-world/src/trigger/release-concurrency.ts

+21
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,24 @@ export const waitReleaseConcurrencyTestTask = task({
147147
};
148148
},
149149
});
150+
151+
export const batchTriggerAndWaitReleaseConcurrency = task({
152+
id: "batch-trigger-and-wait-release-concurrency",
153+
retry: {
154+
maxAttempts: 1,
155+
},
156+
run: async (payload, { ctx }) => {
157+
return await batch.triggerAndWait([
158+
{ id: batchTriggerAndWaitChildTask.id, payload: { waitSeconds: 1 } },
159+
{ id: batchTriggerAndWaitChildTask.id, payload: { waitSeconds: 1 } },
160+
{ id: batchTriggerAndWaitChildTask.id, payload: { waitSeconds: 1 } },
161+
]);
162+
},
163+
});
164+
165+
const batchTriggerAndWaitChildTask = task({
166+
id: "batch-trigger-and-wait-child-task",
167+
run: async (payload: { waitSeconds: number }, { ctx }) => {
168+
await setTimeout(payload.waitSeconds * 1000);
169+
},
170+
});

0 commit comments

Comments
 (0)