Skip to content

Fix infinite loop when hoisting cyclic dependencies#8979

Open
yungsters wants to merge 1 commit intoyarnpkg:masterfrom
yungsters:fix-cyclic-deps
Open

Fix infinite loop when hoisting cyclic dependencies#8979
yungsters wants to merge 1 commit intoyarnpkg:masterfrom
yungsters:fix-cyclic-deps

Conversation

@yungsters
Copy link

Fixes a bug that causes yarn to infinite loop (and subsequently fail by running out of memory).

This makes yarn add @bluejay/[email protected] succeed, a cyclic dependency that currently breaks yarn and was originally reported in #6279.

Test Plan

$ yarn
$ yarn test
$ yarn build

Verified this now succeeds:

$ yarn add @bluejay/[email protected]

Comment on lines +216 to +218
if (parent != null && parent.previousPatterns.has(pattern)) {
return null;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (parent != null && parent.previousPatterns.has(pattern)) {
return null;
}
if (parent?.previousPatterns?.has(pattern)) {
return null;
}

const parts = parentParts.concat(pkg.name);
const key: string = this.implodeKey(parts);
const info: HoistManifest = new HoistManifest(key, parts, pkg, loc, isDirectRequire, isRequired, isIncompatible);
info.previousPatterns = new Set(parent == null ? [] : parent.previousPatterns).add(pattern);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set constructor works fine if the argument is undefined. It will create an empty Set, so we can skip this validation.

Suggested change
info.previousPatterns = new Set(parent == null ? [] : parent.previousPatterns).add(pattern);
info.previousPatterns = new Set(parent?.previousPatterns).add(pattern);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants