Skip to content

Commit 2db277a

Browse files
authored
fix(builder): infinite loop possible on cycle in chain definition (#1832)
1 parent 0501dc4 commit 2db277a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/builder/src/definition.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ function makeFakeChainDefinition(nodes: { [n: string]: any }) {
1212
_.set(rawDef, n, nodes[n]);
1313
}
1414

15-
return new ChainDefinition(rawDef);
15+
const def = new ChainDefinition(rawDef);
16+
17+
try {
18+
def.initializeComputedDependencies();
19+
} catch {
20+
// no contents
21+
}
22+
23+
return def;
1624
}
1725

1826
describe('ChainDefinition', () => {

packages/builder/src/definition.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ export class ChainDefinition {
343343

344344
computeDepsDebug('finished compute dependencies');
345345

346+
const cycles = this.checkCycles();
347+
if (cycles?.length) {
348+
throw new Error(`cannot generate dependency tree: dependency cycle found: ${cycles.join(' => ')}`);
349+
}
350+
346351
this._roots = new Set(this.allActionNames.filter((n) => !this.getDependencies(n).length));
347352

348353
if (computeDepsDebug.enabled) {
@@ -482,8 +487,6 @@ export class ChainDefinition {
482487
currentPath = new Set<string>()
483488
): string[] | null {
484489
// resolved dependencies gets set during dependency computation
485-
this.initializeComputedDependencies();
486-
487490
for (const n of actions) {
488491
if (seenNodes.has(n)) {
489492
return null;

0 commit comments

Comments
 (0)