Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(uses-preload): prevent infinite loop #5184

Merged
merged 3 commits into from
May 12, 2018
Merged

Conversation

patrickhulce
Copy link
Collaborator

fixes an infinite loop on https://emojityper.com/

attacked from multiple prongs:

  • simulator won't try to simulate graphs with cycles
  • graphs with dependency cycles not just dependent cycles are caught
  • fix the creation of a cyclic graph in preload audit

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

nice. thx for these fixes.
one idea

* @return {boolean}
*/
static hasCycle(node) {
static hasCycle(node, direction = 'all') {
if (direction === 'all') {
Copy link
Member

Choose a reason for hiding this comment

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

it seems like the only use we have of this method checks things with the root node, implying we only care about one direction. Maybe we just rename this to hasCycleInDependents until we need the other direction?

Copy link
Member

Choose a reason for hiding this comment

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

wait, isn't it always checking both? Why have an option at all

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

discussed in person, I'll add a comment here

const nodesToExplore = direction === 'dependents' ?
currentNode._dependents :
currentNode._dependencies;
for (const dependent of nodesToExplore) {
Copy link
Member

Choose a reason for hiding this comment

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

call it nextNode or something? Confusing to flatten like that

* @return {boolean}
*/
static hasCycle(node) {
static hasCycle(node, direction = 'all') {
if (direction === 'all') {
Copy link
Member

Choose a reason for hiding this comment

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

wait, isn't it always checking both? Why have an option at all

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM!

@paulirish paulirish merged commit 61e3403 into master May 12, 2018
@paulirish paulirish deleted the fix_preload_infinite_loop branch May 12, 2018 01:16
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.

None yet

3 participants