[BUG] asyncapi cli race condition crash

Open Beginner friendly
#2,293 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
docker, node.js, typescript
Domain
cli, devops

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.

Description

bug
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:

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 `<redacted>`
109.4 
109.4 Caused by:
109.4   process didn't exit successfully: `<redacted>` (exit status: 1)
109.4   --- stdout
109.4   cargo::rerun-if-changed=<redacted>
109.4 
109.4   --- stderr
109.4   Pre-build failed generating API payloads for <redacted> 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:<redacted>
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:

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?
  • I checked and didn't find similar issue
🏢 Have you read the Contributing Guidelines?
Are you willing to work on this issue ?

No, someone else can work on it

Dominant language
TypeScript
Stars
274
Forks
376
Avg merge
12h 11m
Merged PRs (30d)
11

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from asyncapi/cli

All issues in asyncapi/cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.