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

Crash during vite build due to something like infinite loop eating all of the available memory #15288

Closed
7 tasks done
afedotov opened this issue Dec 7, 2023 · 2 comments
Closed
7 tasks done
Labels
duplicate This issue or pull request already exists

Comments

@afedotov
Copy link

afedotov commented Dec 7, 2023

Describe the bug

First of all I've checked #2433, because of OOM error. And none of the workarounds are worked. And looks like it is completely different case. Everything points to that during build vite running into some kind of infinite loop eating all of the available memory, no matter how much you supply, and build ends up with vite node process OOM crash.

Problem is reproducible even in the simple almost empty template project using couple of cubing library submodules/functions. I wondering what in this library can cause such problem with vite.

Can't localize for now, vite build does not produce any of detailed logs during build even if --debug option is supplied. Any suggestions how to trace/debug vite build is appreciated. Already tried to make heap snapshots and V8 profiling, but at this point not all clear for me there:

$ node --heapsnapshot-near-heap-limit 2 ./node_modules/vite/bin/vite.js build
$ node --prof ./node_modules/vite/bin/vite.js build
$ node --prof-process isolate-*-v8.log > v8-profile.txt

Reproduction

https://stackblitz.com/edit/vite-oom-test

Steps to reproduce

Create simple project from template:

$ npm create vite@latest vite-oom-test -- --template vanilla-ts

Install cubing module from npm:

$ cd vite-oom-test/
$ npm install cubing
$ npm update

Replace main.ts with simple usage of that part of cubing library which causes problem:

$ cat <<EOF > src/main.ts

import {
    experimentalSolve3x3x3IgnoringCenters,
    random333Pattern
} from 'cubing/search';

var pattern = await random333Pattern();
var alg = await experimentalSolve3x3x3IgnoringCenters(pattern);
console.log(alg.toString());

EOF

Increase heap size in node as much as possible:

$ export NODE_OPTIONS="--max_old_space_size=16384"

Run vite build and expect infinite loop eating all of the available memory following with OOM crash:

$ npm run build

System Info

System:
    OS: macOS 12.7.1
    CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
    Memory: 4.75 GB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 20.10.0 - /usr/local/bin/node
    npm: 10.2.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 120.0.6099.62
    Safari: 17.1.2
  npmPackages:
    vite: ^5.0.0 => 5.0.6

Used Package Manager

npm

Logs

Click to expand!
> [email protected] build
> tsc && vite build --debug

2023-12-07T15:40:01.562Z vite:config no config file found.
2023-12-07T15:40:01.617Z vite:config using resolved config: {
  root: '/Users/afedotov/tmp/vite-oom-test',
  base: '/',
  mode: 'production',
  configFile: undefined,
  logLevel: undefined,
  clearScreen: undefined,
  optimizeDeps: {
    disabled: 'build',
    force: undefined,
    esbuildOptions: { preserveSymlinks: false }
  },
  build: {
    target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
    cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
    outDir: 'dist',
    assetsDir: 'assets',
    assetsInlineLimit: 4096,
    cssCodeSplit: true,
    sourcemap: false,
    rollupOptions: {},
    minify: 'esbuild',
    terserOptions: {},
    write: true,
    emptyOutDir: null,
    copyPublicDir: true,
    manifest: false,
    lib: false,
    ssr: false,
    ssrManifest: false,
    ssrEmitAssets: false,
    reportCompressedSize: true,
    chunkSizeWarningLimit: 500,
    watch: null,
    commonjsOptions: { include: [Array], extensions: [Array] },
    dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] },
    modulePreload: { polyfill: true },
    cssMinify: true
  },
  configFileDependencies: [],
  inlineConfig: {
    root: undefined,
    base: undefined,
    mode: undefined,
    configFile: undefined,
    logLevel: undefined,
    clearScreen: undefined,
    optimizeDeps: { force: undefined },
    build: {}
  },
  rawBase: '/',
  resolve: {
    mainFields: [ 'browser', 'module', 'jsnext:main', 'jsnext' ],
    conditions: [],
    extensions: [
      '.mjs',  '.js',
      '.mts',  '.ts',
      '.jsx',  '.tsx',
      '.json'
    ],
    dedupe: [],
    preserveSymlinks: false,
    alias: [ [Object], [Object] ]
  },
  publicDir: '/Users/afedotov/tmp/vite-oom-test/public',
  cacheDir: '/Users/afedotov/tmp/vite-oom-test/node_modules/.vite',
  command: 'build',
  ssr: {
    target: 'node',
    optimizeDeps: { disabled: true, esbuildOptions: [Object] }
  },
  isWorker: false,
  mainConfig: null,
  isProduction: true,
  plugins: [
    'vite:build-metadata',
    'vite:watch-package-data',
    'vite:pre-alias',
    'alias',
    'vite:modulepreload-polyfill',
    'vite:resolve',
    'vite:html-inline-proxy',
    'vite:css',
    'vite:esbuild',
    'vite:json',
    'vite:wasm-helper',
    'vite:worker',
    'vite:asset',
    'vite:wasm-fallback',
    'vite:define',
    'vite:css-post',
    'vite:build-html',
    'vite:worker-import-meta-url',
    'vite:asset-import-meta-url',
    'vite:force-systemjs-wrap-complete',
    'commonjs',
    'vite:data-uri',
    'vite:dynamic-import-vars',
    'vite:import-glob',
    'vite:build-import-analysis',
    'vite:esbuild-transpile',
    'vite:terser',
    'vite:reporter',
    'vite:load-fallback'
  ],
  css: { lightningcss: undefined },
  esbuild: { jsxDev: false },
  server: {
    preTransformRequests: true,
    sourcemapIgnoreList: [Function: isInNodeModules$1],
    middlewareMode: false,
    fs: { strict: true, allow: [Array], deny: [Array] }
  },
  preview: {
    port: undefined,
    strictPort: undefined,
    host: undefined,
    https: undefined,
    open: undefined,
    proxy: undefined,
    cors: undefined,
    headers: undefined
  },
  envDir: '/Users/afedotov/tmp/vite-oom-test',
  env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  assetsInclude: [Function: assetsInclude],
  logger: {
    hasWarned: false,
    info: [Function: info],
    warn: [Function: warn],
    warnOnce: [Function: warnOnce],
    error: [Function: error],
    clearScreen: [Function: clearScreen],
    hasErrorLogged: [Function: hasErrorLogged]
  },
  packageCache: Map(1) {
    'fnpd_/Users/afedotov/tmp/vite-oom-test' => {
      dir: '/Users/afedotov/tmp/vite-oom-test',
      data: [Object],
      hasSideEffects: [Function: hasSideEffects],
      webResolvedImports: {},
      nodeResolvedImports: {},
      setResolvedCache: [Function: setResolvedCache],
      getResolvedCache: [Function: getResolvedCache]
    },
    set: [Function (anonymous)]
  },
  createResolver: [Function: createResolver],
  worker: { format: 'iife', plugins: '() => plugins', rollupOptions: {} },
  appType: 'spa',
  experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
  getSortedPlugins: [Function: getSortedPlugins],
  getSortedPluginHooks: [Function: getSortedPluginHooks]
}
vite v5.0.6 building for production...
transforming...

<--- Last few GCs --->

[6435:0x7ff145100000]   443850 ms: Mark-Compact 16109.8 (16419.5) -> 16098.9 (16424.5) MB, 27278.40 / 0.09 ms  (average mu = 0.091, current mu = 0.007) task; scavenge might not succeed
[6435:0x7ff145100000]   471715 ms: Mark-Compact 16115.3 (16425.0) -> 16105.3 (16431.5) MB, 27674.23 / 0.06 ms  (average mu = 0.051, current mu = 0.007) allocation failure; scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x100cec755 node::Abort() [/usr/local/bin/node]
 2: 0x100cec936 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [/usr/local/bin/node]
 3: 0x100e9c91c v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/usr/local/bin/node]
 4: 0x10108cac7 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
 5: 0x101091097 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/usr/local/bin/node]
 6: 0x10108d3e5 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*) [/usr/local/bin/node]
 7: 0x10108ae80 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
 8: 0x10107fb91 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
 9: 0x1010805d5 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x1010626c2 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/usr/local/bin/node]
11: 0x1014e04c0 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
12: 0x1018b2136 Builtins_CEntry_Return1_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
13: 0x1018909b0 Builtins_ObjectEntries [/usr/local/bin/node]
14: 0x10c0cc75d 
sh: line 1:  6435 Abort trap: 6           vite build --debug

Validations

Copy link

stackblitz bot commented Dec 7, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sapphi-red
Copy link
Member

Duplicate of #14499, #7015

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Dec 9, 2023
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Dec 9, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants