[BUG] asyncapi cli race condition crash
- Dominant language
- TypeScript
- Stars
- 272
- Forks
- 375
- Avg merge
- 3h 22m
- Merged PRs (30d)
- 8
Description
### Describe the bug.
Asyncapi cli 6.0.0 seems to sometimes crash when invoked many times in parallel in docker. It crashes with the following error:
```
Error: EEXIST: file already exists, mkdir
'/usr/local/lib/node_modules/@asyncapi/cli/lib/utils/logs'
Code: EEXIST
```
which suggests that the crash might be caused by the following in [logger.ts](https://github.com/asyncapi/cli/blob/v6.0.2/src/utils/logger.ts#L6):
```typescript
const logDir: string = path.join(__dirname, config.has('log.dir') ? config.get('log.dir') : 'logs');
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir);
}
```
This is extremely unlikely to cause issues on a normal system because the folder gets created once and then never again but that's not the case in a fresh docker container. It's still very rare there, I've seen the crash just once myself and once on a colleague's machine, but it can happen.
Can't contribute a PR sadly because I'm not a TypeScript developer.
### Expected behavior
asyncapi not crashing with `EEXIST: file already exists, mkdir '/usr/local/lib/node_modules/@asyncapi/cli/lib/utils/logs'`
### Screenshots
Error log from one of the crashes. Happened as part of `cargo build` that runs `asyncapi generate` internally.
```
109.4 error: failed to run custom build command for ``
109.4
109.4 Caused by:
109.4 process didn't exit successfully: `` (exit status: 1)
109.4 --- stdout
109.4 cargo::rerun-if-changed=
109.4
109.4 --- stderr
109.4 Pre-build failed generating API payloads for error: WARNING: NODE_ENV value of 'production' did not match any deployment config file names.
109.4 WARNING: See https://github.com/node-config/node-config/wiki/Strict-Mode
109.4 WARNING: No configurations found in configuration directory:
109.4 WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.
109.4 Error: EEXIST: file already exists, mkdir
109.4 '/usr/local/lib/node_modules/@asyncapi/cli/lib/utils/logs'
109.4 Code: EEXIST
109.4
109.4 warning: build failed, waiting for other jobs to finish...
```
### How to Reproduce
Wasn't able to reliably reproduce with `asyncapi` cli outside of our docker image. The following shows a similar error though:
```bash
export NPM_CONFIG_PREFIX="$(mktemp -d)"
trap 'rm -rf "$NPM_CONFIG_PREFIX"' EXIT
npm install -g @asyncapi/cli@6.0.2
cd "$(npm root -g)/@asyncapi/cli"
export SUPPRESS_NO_CONFIG_WARNING=true
for round in {1..100}; do
rm -rf lib/utils/logs
for i in $(seq 1 8); do
node -e "require('./lib/utils/logger')" &
done
wait
done
```
### 🖥️ Device Information [optional]
_No response_
### 👀 Have you checked for similar open issues?
- [x] I checked and didn't find similar issue
### 🏢 Have you read the Contributing Guidelines?
- [x] I have read the [Contributing Guidelines](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md)
### Are you willing to work on this issue ?
No, someone else can work on it
Contributor guide
Research direction
Start with src/utils/logger.ts, especially the log directory creation shown in the issue. Run the provided parallel shell reproduction after installing @asyncapi/cli@6.0.2, then verify repeated concurrent invocations no longer fail with EEXIST while creating logs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, node.js, typescript
- Domain
- cli, devops
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100