aws / aws/aws-cdk

python/aws_cdk: synth lock file not released on python subprocess error

Open
#24,946 13 comments 11 reactions 0 assignees View on GitHub
bug effort/medium p2 package/tools
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

When `cdk synth` is run and the underlying Python code raises an Exception, e.g. due to a syntax error, the next run of synth fails with:

`Another CLI (PID=1) is currently synthing to cdk.out. Invoke the CLI in sequence, or use '--output' to synth into different directories.`

This appears to happen because the lock file in `cdk.out/synth.lock` is not released.

This is normally not noticed because the PID in the lock file is no longer live - https://github.com/aws/aws-cdk/blob/6d581d7d4a0107dc5acd532c603f90d253d8f72e/packages/aws-cdk/lib/api/util/rwlock.ts#L7 ; however when running CDK within a docker container then PIDs reoccur

### Expected Behavior

`cdk.out/synth.lock` is released

### Current Behavior

`cdk.out/synth.lock` is not released causing `Another CLI (PID=1) is currently synthing to cdk.out.
Invoke the CLI in sequence, or use '--output' to synth into different directories.`
to be raised on the next synth command unless the lock file is manually removed.

### Reproduction Steps

1. Add `assert 0` or something that will raise an exception in a Python CDK app
2. Run `cdk synth` for that app within docker
3. Run `cdk synth` again within docker and observe the issue because 2 and 3 have the same PID

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.72.1

### Framework Version

_No response_

### Node.js Version

18.13.0

### OS

Debian GNU/Linux 11

### Language

Python

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in packages/aws-cdk/lib/api/util/rwlock.ts and reproduce the failure with a Python CDK app inside Docker. Trace what happens to cdk.out/synth.lock when the Python subprocess raises an exception; done means a failed synth releases the lock and a second synth in the same container succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, python, typescript
Domain
cli, cloud, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.