Skip to content

Vite leaving zombie esbuild process when parent process exists #5743

Description

@thiagomajesk

Describe the bug

When using Vite with Phoenix's dev watcher the process doesn't shut down and keeps running in the background after the parent process is stopped. This is a follow-up on this closed PR: #1857 and #3659.

It seems that the fix was reverted because people were still having other problems with @nullpilot proposed solution.
However, by running top -bc -n 1 | grep esbuild I can see that the previous process still lingers.

By doing a little research, I manage to find a temporary solution that I can apply directly to my vite.config.js file:

import { defineConfig } from "vite";

export default defineConfig(({command}) => {
  maybeCloseStdin(command)
  return { // [...] }
})

function maybeCloseStdin(command) {
  if (command == "build") return
  process.stdin.on("close", () => { process.exit(0) })
  process.stdin.resume()
}

This is what the Phoenix watcher runs through npm run watch:
vite build --watch --minify false --emptyOutDir false --clearScreen false --mode development.

PS.: I was wondering if a --watch-stdin flag or something similar would solve this in the same way it did for Webpack.

Reproduction

See previous issues linked to the report

System Info

System:
    OS: Linux 5.10 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
    Memory: 420.44 MB / 1.94 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 14.9.0 - ~/.asdf/installs/nodejs/14.9.0/bin/node
    npm: 6.14.8 - ~/.asdf/installs/nodejs/14.9.0/bin/npm

Used Package Manager

npm

Logs

No response

Validations

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions