Skip to content

fix(nest): prevent concurrent NestJS application initialization#140

Open
lnqs wants to merge 1 commit intoaxe-me:mainfrom
lnqs:prevent-concurrent-nestjs-initialization
Open

fix(nest): prevent concurrent NestJS application initialization#140
lnqs wants to merge 1 commit intoaxe-me:mainfrom
lnqs:prevent-concurrent-nestjs-initialization

Conversation

@lnqs
Copy link
Copy Markdown

@lnqs lnqs commented Apr 4, 2026

Added a locking mechanism to ensure only one NestJS application is initialized at a time, avoiding potential race conditions during simultaneous requests.

Added a locking mechanism to ensure only one NestJS application is
initialized at a time, avoiding potential race conditions during
simultaneous requests.
@lnqs
Copy link
Copy Markdown
Author

lnqs commented Apr 4, 2026

I'm working on a NestJS app using vite-plugin-node with a React frontend that triggers multiple requests at the same time. This reliably lead to all kind weird errors right after the dev server was started, when the web frontend was still open in the browser. After some investigation, I realized the NestJS app was initialized multiple times.

This fix locks (deadly stupid, with a busy lock) the NestJS initializing to prevent this issue. Seems to work on my project.
A cleaner approach would probably be to have some kind of async lock in place, but I don't think it's worth adding a new dependency or more complex code. The performance impact of the loop and timeout shouldn't be relevant, given this happens only on app start or reload and when multiple requests are performed at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant