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

fix(assertions): stack overflow while parsing template #26767

Merged
merged 2 commits into from
Aug 18, 2023

Conversation

Chriscbr
Copy link
Contributor

@Chriscbr Chriscbr commented Aug 15, 2023

Closes #26766

The function findCycle tries to find a cycle by using a depth-first search (DFS). The DFS is implemented recursively in the recurse function. For each node, it tries to find a path that eventually leads back to the start of the path. If such a path is found, a cycle exists, and the nodes forming this cycle are returned.

One of the bugs in the current implementation is that it only checks whether the current dependency dep is equal to the first node of the current path path[0]. This means it will only detect a cycle if the cycle includes the first node of the search, which might not always be the case.

To fix this, the function should check whether the current dependency dep is already somewhere in the current path path. If it is, then a cycle has been found.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team August 15, 2023 22:04
@github-actions github-actions bot added bug This issue is a bug. p2 admired-contributor [Pilot] contributed between 13-24 PRs to the CDK labels Aug 15, 2023
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@Chriscbr
Copy link
Contributor Author

exemption request please 🙂

@aws-cdk-automation aws-cdk-automation added pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Aug 15, 2023
Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

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

Hi @Chriscbr :) Can you provide a bit more in the PR description explaining how this is the root cause for the stack overflow issue?

@@ -1345,6 +1345,29 @@ describe('Template', () => {
}).toThrow(/dependency cycle/);
});

test('throws when given a more complex template with cyclic dependencies', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

While i can see how the change in cyclic.ts makes the recurse function more efficient, this test isn't going to show that one way or another right? the test will succeed with the old code as well?

I'm prepared to just approve as is anyway, because this looks low risk and is hard to test, but want to make sure i have the whole picture first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially ran the test with the old code (unchanged) and it fails for me because of a stackoverflow error.
Screenshot 2023-08-17 at 5 46 06 PM

I think the call stack in the test case I added ends up looking like this (without the fix applied):

findCycle(deps)
recurse("Res1", ["Res1"])
recurse("Res2", ["Res1", "Res2"])
recurse("Res3", ["Res1", "Res2", "Res3"])
recurse("Res2", ["Res1", "Res2", "Res3", "Res2"])
recurse("Res3", ["Res1", "Res2", "Res3", "Res2", "Res3"])
...

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah i see

@kaizencc kaizencc added pr-linter/exempt-integ-test The PR linter will not require integ test changes and removed pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. labels Aug 17, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review August 17, 2023 14:05

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@github-actions github-actions bot added the effort/medium Medium work item – several days of effort label Aug 17, 2023
@Chriscbr
Copy link
Contributor Author

@kaizencc I updated the description 🙏

Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

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

Thanks @Chriscbr

@mergify
Copy link
Contributor

mergify bot commented Aug 18, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Aug 18, 2023
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 55f3239
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 01a7b5b into aws:main Aug 18, 2023
11 checks passed
@mergify
Copy link
Contributor

mergify bot commented Aug 18, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

assertions: Maximum call stack size exceeded when parsing template
3 participants