Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Memory Leak in Dev Server Causing System to Run Out of Application Memory #8976

Open
Fausto95 opened this issue Jan 8, 2025 · 10 comments
Assignees

Comments

@Fausto95
Copy link

Fausto95 commented Jan 8, 2025

Version

System:
    OS: macOS 14.6.1
    CPU: (11) arm64 Apple M3 Pro
    Memory: 119.66 MB / 18.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Safari: 17.6
  npmPackages:
    @rsbuild/[email protected]
    @rsbuild/[email protected]

Details

While using rsbuild dev, I encountered a significant memory leak that caused the system to run out of application memory. This issue makes the system unstable and forces the user to quit applications to free up resources.

Image

CodeSandbox: https://codesandbox.io/p/github/Fausto95/react-native-web-rsbuild/main?import=true

Reproduce link

https://github.com/Fausto95/react-native-web-rsbuild

Reproduce Steps

  1. pnpm install
  2. pnpm start:web
  3. Keep on applying changes to /apps/rnw/src/App.js
  4. Use Activity Monitor and observe the continuous increase in memory usage for the rsbuild-node process
@9aoy 9aoy transferred this issue from web-infra-dev/rsbuild Jan 9, 2025
@uladzimirdev
Copy link

I can report the same issue with rspack, rspack-node process can take ~30Gb of RAM.

I use @rspack/[email protected], rspack config can be found here

@h-a-n-a
Copy link
Contributor

h-a-n-a commented Jan 17, 2025

Not sure how to reproduce this amount of memory consumption, but I found there might be something related to memory reseting in mimalloc. I changed memory semantic from MADV_FREE to MADV_DONTNEED to reflect memory consumption accurately in statistics like RSS.

@uladzimirdev
Copy link

@h-a-n-a I'm ready to test possible fixes as just running dev server for a while increases memory consumption for me, it wasn't a problem in v1

@h-a-n-a
Copy link
Contributor

h-a-n-a commented Jan 17, 2025

@h-a-n-a I'm ready to test possible fixes as just running dev server for a while increases memory consumption for me, it wasn't a problem in v1

@uladzimirdev Do you mind adding a reproducible demo? Which version of rspack do you use that doesn't have this issue? You may also try @rspack-canary/[email protected]

@uladzimirdev

This comment has been minimized.

@1yasa
Copy link

1yasa commented Jan 20, 2025

Image

+1 leaking at macos intel.

@h-a-n-a
Copy link
Contributor

h-a-n-a commented Jan 21, 2025

@h-a-n-a

this is what I got on rspack serve

/node_modules/@rspack/cli/node_modules/@rspack/core/dist/index.js:14665
[js]     this.#instance = new instanceBinding.Rspack(
[js]                      ^
[js]
[js] Error: Missing field `enforceRelative`
[js]
[js]     at #getInstance (/node_modules/@rspack/cli/node_modules/@rspack/core/dist/index.js:14665:22)
[js]     at #build (/node_modules/@rspack/cli/node_modules/@rspack/core/dist/index.js:13879:22)
[js]     at /node_modules/@rspack/cli/node_modules/@rspack/core/dist/index.js:13851:18
[js]     at done (/node_modules/@rspack/lite-tapable/dist/index.js:473:13)
[js]     at AsyncSeriesHook.callAsyncStageRange (/node_modules/@rspack/lite-tapable/dist/index.js:480:20)
[js]     at AsyncSeriesHook.callAsync (/node_modules/@rspack/lite-tapable/dist/index.js:82:21)
[js]     at _Compiler.compile (/node_modules/@rspack/cli/node_modules/@rspack/core/dist/index.js:13845:30)
[js]     at /node_modules/@rspack/cli/node_modules/@rspack/core/dist/index.js:13251:21
[js]     at done (/node_modules/@rspack/lite-tapable/dist/index.js:473:13)
[js]     at next (/metabase/node_modules/@rspack/lite-tapable/dist/index.js:533:25) {
[js]   code: 'GenericFailure'
[js] }
[js]
[js] Node.js v18.20.5
error Command failed with exit code 1.

@uladzimirdev Would you please try again with install-rspack?

@uladzimirdev
Copy link

uladzimirdev commented Jan 21, 2025

@h-a-n-a I used it to install canary, let me try one more time.

yeah, no difference. It looks like it happens mostly when I switch branches without restarting dev server, memory grows with every HMR in action

@hnrchrdl
Copy link

Same here. Our application starts out with under 2GB of RAM usage for the rspack-node process, and easily accumulates around 20GB during usage. We are on 1.2.1 and i am using a Apple M3 Pro.

Are there any plans to investigate / fix this? Thank you for consideration.

@rafael-zilberman
Copy link

Same for us, when starting rspack the memory usage is ±4GB and growth to around 50GB while developing.
Using 1.2.1 with Apple M2 Pro

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

No branches or pull requests

6 participants