Repository navigation
Conversation
Removes unused config import and unnecessary filesystem directory creation in src/utils/logger.ts. This eliminates spurious node-config warning messages printed on stderr across CLI commands when running in production environments, and avoids race condition crashes caused by concurrent directory creation. Fixes asyncapi#2323 Fixes asyncapi#2293
There was a problem hiding this comment.
Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.
Azizzzss
left a comment
There was a problem hiding this comment.
Thanks for picking up #2323 so quickly. The change to src/utils/logger.ts matches what I found: nothing ever writes to that folder, so removing the block is the right fix, and it also removes the mkdirSync race from #2293 (note that #2294 patches the same lines, so maintainers may want to decide which one to keep).
Two small notes on test/unit/utils/logger.test.ts, which I ran on Windows 11 with Node 24:
-
should not emit node-config warnings on stderrspawnsrequire('./lib/utils/logger'), so it needs a priornpm run build. Withnpm run unit:testalone (nolib/), it fails withCannot find module './lib/utils/logger'. CI is fine becausenpm testruns the build first, but the DEVELOPMENT.md flow (npm run unit:test,npm run test:one) will fail for anyone who has not built. One option is to spawn with-r ts-node/registerand require./src/utils/logger.tsinstead, so the test does not depend on the build output. -
should not create an unused logs directory at module pathchecks thatlib/utils/logsdoes not exist. On a machine that ran the old code before, that folder is still there until the nextrimraf lib, so the test fails locally even though the new code is correct. Removing the folder in abefore()hook, or checking the source folder only, would make it stable.
Everything else looks good to me.
…est environment - Spawn child process with -r ts-node/register to test src/utils/logger.ts directly without requiring a prior npm run build. - Clean up any pre-existing logs folders in a beforeEach hook to ensure test stability across local runs.
|
|
Thanks for the detailed review and feedback @Azizzzss! I've addressed both points in the latest commit:
|
|



Description
Running CLI document commands (such as
asyncapi validate,asyncapi convert,asyncapi bundle, etc.) or importing@asyncapi/cliin production environments caused fournode-configwarning messages to be printed to stderr:Additionally, concurrent invocations (e.g. in parallel CI workflows or multi-process containers) could encounter an unhandled
EEXISTrace condition due to synchronous directory creation at module load time.Root Cause
In
src/utils/logger.ts,node-config,fs, andpathwere unconditionally imported and evaluated at module load time to compute and createlogDir. However:winstononly configures aConsoletransport; no file-based logging transport is used in the logger utility.@oclifand custom context configs, notnode-config(which is only utilized bysrc/apps/api).fs.mkdirSync(logDir)unconditionally whenlogger.tsis imported creates an unneededlogsdirectory and causes filesystem race condition crashes when multiple CLI instances launch concurrently.Changes Proposed
config,fs, andpathimports and the directory creation logic fromsrc/utils/logger.ts.test/unit/utils/logger.test.tsto verify logger initialization, stream message forwarding, absence of filesystem directory creation, and clean stderr output in production mode withoutNODE_CONFIG_DIR.Testing
npm run lint: Passed with 0 errors and 0 warnings.npm run build: Compiled successfully without stderr warnings.npm run test:one -- test/unit/utils/logger.test.ts: 4/4 passing (100% statement, branch, func, and line coverage onsrc/utils/logger.ts).npm run unit:test: 234 passing.Fixes #2323
Fixes #2293