Skip to content

Instantly share code, notes, and snippets.

@affinage-digital
Last active June 27, 2023 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save affinage-digital/9ed8b7d6a852e8be02589baa69b97eca to your computer and use it in GitHub Desktop.
Save affinage-digital/9ed8b7d6a852e8be02589baa69b97eca to your computer and use it in GitHub Desktop.
Esbuild, vite, nuxt, nitro multi-threading problem

Sometimes when deploy and publishing a project on a hosting, an error may occur:

[vite:esbuild] The service is no longer running: write EPIPE
[vite:esbuild-transpile] The service was stopped: write EPIPE
esbuild-transpile The service was stopped: write EPIPE
fatal error: go routine deadlock
runtime: failed to create new OS thread (have 14 already; errno=11)
runtime: may need to increase max user processes (ulimit -u)
fatal error: newosproc

... and so on

Details

The reason why there is an error in limiting the number of parallel processes and treads. This is a common situation for shared servers. Example unix command ulimit -u result 100 threads, not 10 000 threads.

esbuild write on Go and goroutine uses max multithreading. esbuild have compiled version of go-sources /node_modules/@esbuild/linux-x64/bin/esbuild without the ability to influence the maximum number of threads (runtime.GOMAXPROCS() or debug.SetMaxThreads())

Is it possible to solve the problem?

Yes. Every time then you exec npm run build you must set variable GOMAXPROCS

Examples:

Before

npm run dev

After

export GOMAXPROCS=1
npm run dev

The variable GOMAXPROCS=1 says that the number of parallel goroutine processes should be limited to single-threading. And now your esbuild transform or render chunks cannot stopped and crash process by OS.


The problem was found on nuxt3 which used esbuild three times:

  1. Client build (from vite and rollup)
  2. Server build (from vite and rollup)
  3. Nitro build (from rollup)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment