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

(cli): cdk watch does not recover if there is an error in cdk stack/app #27864

Closed
ssingh-01 opened this issue Nov 6, 2023 · 3 comments · Fixed by #30874
Closed

(cli): cdk watch does not recover if there is an error in cdk stack/app #27864

ssingh-01 opened this issue Nov 6, 2023 · 3 comments · Fixed by #30874
Assignees
Labels
bug This issue is a bug. cli Issues related to the CDK CLI effort/small Small work item – less than a day of effort p2 package/tools Related to AWS CDK Tools or CLI

Comments

@ssingh-01
Copy link

ssingh-01 commented Nov 6, 2023

Describe the bug

If I made an error that does not resolve into a valid cloudformation, cdk watch throws the error on console. However, if I fix that issue, I would expect cdk to detect the issue to resolve and deploy the correct cloudformation template. CDK watch gets hung instead.

Expected Behavior

Expect cdk watch to redeploy once the error has been fixed.

Current Behavior

If I made an error that does not resolve into a valid cloudformation, cdk watch throws the error on console. However, if I fix that issue, CDK watch gets hung. It detects the change but does not deploy.

Reproduction Steps

This is a valid stack and app :

app = App()
ApiEventBridgeLambdaStack(app, "ApiEventBridgeLambdaStack")

If I update it to the following while cdk watch is running, cdk watch will throw the error but stays hung after I fix the error (remove a mistyped N in this case):

app = App()
ApiEventBridgeLambdaStack(appN, "ApiEventBridgeLambdaStack")

This happens with stack level changes as well.

Detects change but does not deploy, stays in hung state :

image

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

v2.100.0

Framework Version

No response

Node.js Version

v18.16.0

OS

MAC

Language

Python

Language Version

3.10.6

Other information

Reproducible with typescript too
Workaround is to interrupt the terminal and re run cdk watch.

@ssingh-01 ssingh-01 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 6, 2023
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Nov 6, 2023
@khushail
Copy link
Contributor

khushail commented Nov 6, 2023

thanks @ssingh-01 for reporting this.

@khushail khushail added effort/small Small work item – less than a day of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Nov 6, 2023
@SankyRed SankyRed self-assigned this Apr 30, 2024
@pahud pahud added the cli Issues related to the CDK CLI label May 29, 2024
@misterjoshua
Copy link
Contributor

I'm running into this issue as well. I've been working around the issue with ctrl c and re-running cdk watch.

I think the issue is that the cdk cli isn't releasing the outdir lock when a synth fails. The problem is here:

const writerLock = await new RWLock(outdir).acquireWrite();

I think the lines that follow should live in a try/catch - when the exec fails, I think the catch should probably release the lock and rethrow the error.

@mergify mergify bot closed this as completed in #30874 Sep 16, 2024
mergify bot pushed a commit that referenced this issue Sep 16, 2024
### Issue # (if applicable)

Closes #27864

### Reason for this change

When using cdk watch mode, a synth failure causes the CDK CLI to no longer deploy changes. The CDK CLI must be restarted to resume watch mode. The cause of the issue is that CDK CLI never releases the outdir write lock if synthing fails, so subsequent attempts to exec the user's app cannot acquire the outdir writer lock.



### Description of changes

I added a try/catch that releases the outdir writer lock & rethrows the error when a synth fails.



### Description of how you validated changes

I added a unit test. I also ran the modified cdk cli on a project of my own and simulated the failure of a synth to see whether the issue was resolved, and it is.



### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

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

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. cli Issues related to the CDK CLI effort/small Small work item – less than a day of effort p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants