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

After the build is completed, the esbuild process does not exit #3558

Closed
peakchen90 opened this issue Dec 19, 2023 · 6 comments
Closed

After the build is completed, the esbuild process does not exit #3558

peakchen90 opened this issue Dec 19, 2023 · 6 comments

Comments

@peakchen90
Copy link

When I use esbuild.build api to build, the node process does not exit, but esbuild cannot exit either.

The reproduce code:

const esbuild = require('esbuild');

(async () => {
  await esbuild.build({
    entryPoints: ['./src'],
  });

  console.log(' >>> done');
})();

setTimeout(() => {
  // keep running...
}, 10000000);

The terminal output screenshot:
image

The MacOS monitor screenshot:
image

I discovered this problem because my team member reported that running esbuild watch mode used 54G of memory on his computer.
image

@evanw
Copy link
Owner

evanw commented Dec 19, 2023

setTimeout(() => {
  // keep running...
}, 10000000);

This is why your node process keeps running. That is not surprising.

Once activated, the esbuild process stays around until node exits (for performance reasons), but should not keep node open due to how node's child process reference counting works.

If you have a way to reproduce either the problem of esbuild keeping node open, or of esbuild using >50gb of memory, then please provide it here. In the meantime I'm marking this issue as unactionable because there's nothing I can do with it.

@anatoliyarkhipov
Copy link

anatoliyarkhipov commented Dec 19, 2023

I have a similar problem: after building I start express to host the built files (it's a production script):

  await esbuild.build(config)
  express().use("/media", express.static("media")).listen(3002)

And the process consumes a bunch of memory:

image

The more entry-points I had the more memory is consumed.

I tried to start only express, just in case, and it takes around 30mb.

Is there a way to tell ESBuild to calm down without moving it to a separate process?

@peakchen90
Copy link
Author

@evanw Is it possible to implement an api that can manually exit the esbuild child process, because I will only run esbuild.build once, and then never run it again, and it keeps using memory?

@evanw
Copy link
Owner

evanw commented Dec 22, 2023

Yes. There used to be an API for this but it was removed after #656 was implemented as it was not necessary (see version 0.9.0). However, the Deno API for esbuild currently does have a stop() function because Deno (at least at the time) didn't have a way to allow child processes to exit automatically when the parent process exits. So I can consider putting stop() back for the node API as well.

However, it would still be good to have a way to reproduce esbuild using >50gb of memory. That sounds like a bug unless you're doing something unusual with esbuild.

evanw added a commit that referenced this issue Dec 22, 2023
@evanw evanw closed this as completed in 914f608 Dec 22, 2023
@peakchen90
Copy link
Author

@evanw OK, thanks a lot.

I use esbuild to pre-build the node_modules code, and then compile the source code (src) with webpack. The usage code in watch mode is as following:

const ctx = await esbuild.context(buildOptions);
await ctx.watch(); 

And I cannot reproduce esbuild useing more than 50G of memory (in my computer), so I want to avoid this problem by exiting esbuild manually.

@caramboleyo
Copy link

on deno the stop function does nothing
weird subprocesses remain forever (i also only need it once at startup)

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

4 participants