wmr icon indicating copy to clipboard operation
wmr copied to clipboard

Build segfaults on Node.js v16 if config contains empty middleware array

Open zgoda opened this issue 4 years ago • 12 comments

Describe the bug If config contains empty array of middlewares, wmr run build ends with segfault.

To Reproduce Steps to reproduce the behavior:

  1. Initialise new project with npm init wmr@latest myproject, cd to myproject
  2. In wmr.config.mjs add middleware: [] to config object
  3. Run npm run build
  4. See error

Expected behavior Build finishes successfully

Bug occurs with:

  • [ ] wmr or wmr start (development)
  • [x] wmr build (production)
  • [ ] wmr serve

Desktop (please complete the following information):

  • OS: Ubuntu 20.04.3
  • Browser: N/A
  • Node Version: 16.13.0; NPM Version: 8.1.2
  • WMR Version: 3.7.2

Additional context Sometimes build finishes fine if middleware is null or undefined but fails at random. When set to empty array build failed in 20/20 attempts.

zgoda avatar Oct 31 '21 11:10 zgoda

Can you provide the error please?

I cannot reproduce, and I don't believe middlewares are used in any part of the build process.

rschristian avatar Oct 31 '21 22:10 rschristian

This is segfault.

$ npm run build

> build
> wmr build --prerender

Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating

Wrote 23Kb to disk:
  dist/index.html 460b
  dist/index.d5d2e732.js 17Kb
  dist/assets/style.e6ee4bcf.css 499b
  dist/chunks/prerender.ea3dab95.js 4.8Kb
  dist/chunks/index.fb97a71f.js 214b
Segmentation fault (core dumped)

Config that does not segfault:

import { defineConfig } from 'wmr';

// Full list of options: https://wmr.dev/docs/configuration
export default defineConfig({
    /* Your configuration here */
    alias: {
        react: 'preact/compat',
        'react-dom': 'preact/compat'
    }
});

Config that segfaults always:

import { defineConfig } from 'wmr';

// Full list of options: https://wmr.dev/docs/configuration
export default defineConfig({
    /* Your configuration here */
    alias: {
        react: 'preact/compat',
        'react-dom': 'preact/compat'
    },
    middleware: []
});

If middleware is null then segfaults happen at random.

zgoda avatar Nov 02 '21 11:11 zgoda

That's really interesting. Can you share the debug info? wmr build --debug

rschristian avatar Nov 02 '21 15:11 rschristian

And on Mac OS 11.6.1 (node & npm versions exactly as on my Linux box):

$ npm run build

> build
> wmr build --prerender

Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating

Wrote 23Kb to disk:
  dist/index.html 460b
  dist/index.8a0cfff0.js 17Kb
  dist/assets/style.e6ee4bcf.css 499b
  dist/chunks/prerender.c8def485.js 4.8Kb
  dist/chunks/index.a1e0eb1d.js 214b
Segmentation fault: 11

Debug output from MacOS:

$ node_modules/.bin/wmr build --prerender --debug
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating
  wmr:config  {
  wmr:config    _: [],
  wmr:config    prerender: true,
  wmr:config    debug: true,
  wmr:config    cwd: '/Users/jarekzgoda/work/test0',
  wmr:config    public: 'public',
  wmr:config    out: '/Users/jarekzgoda/work/test0/dist',
  wmr:config    sourcemap: undefined,
  wmr:config    visualize: undefined,
  wmr:config    minify: true,
  wmr:config    root: '/Users/jarekzgoda/work/test0/public',
  wmr:config    plugins: [],
  wmr:config    output: [],
  wmr:config    middleware: [],
  wmr:config    features: { preact: true },
  wmr:config    alias: { react: 'preact/compat', 'react-dom': 'preact/compat' },
  wmr:config    customRoutes: [],
  wmr:config    prod: true,
  wmr:config    mode: 'build',
  wmr:config    env: {},
  wmr:config    overlayDir: '/Users/jarekzgoda/work/test0/dist',
  wmr:config    publicPath: '/',
  wmr:config    host: 'localhost'
  wmr:config  }
  npm:plugin  htm/preact -> npm/[email protected]/preact/index.module.js
  npm:plugin  preact-iso -> npm/[email protected]/index.js
  npm:plugin  htm/preact -> npm/[email protected]/preact/index.module.js
  npm:plugin  htm/preact -> npm/[email protected]/preact/index.module.js
  npm:plugin  htm/preact -> npm/[email protected]/preact/index.module.js
  npm:plugin  preact-iso -> npm/[email protected]/index.js
  npm:plugin  preact/hooks -> npm/[email protected]/hooks/dist/hooks.module.js
  npm:plugin  htm/preact -> npm/[email protected]/preact/index.module.js
  npm:plugin  preact -> npm/[email protected]/dist/preact.module.js
  npm:plugin  htm -> npm/[email protected]/dist/htm.module.js
  npm:plugin  ./router.js -> npm/[email protected]/router.js
  npm:plugin  ./lazy.js -> npm/[email protected]/lazy.js
  npm:plugin  ./hydrate.js -> npm/[email protected]/hydrate.js
  npm:plugin  ./prerender.js -> npm/[email protected]/prerender.js
  npm:plugin  preact -> npm/[email protected]/dist/preact.module.js
  npm:plugin  preact -> npm/[email protected]/dist/preact.module.js
  npm:plugin  preact -> npm/[email protected]/dist/preact.module.js
  npm:plugin  preact -> npm/[email protected]/dist/preact.module.js
  npm:plugin  preact/hooks -> npm/[email protected]/hooks/dist/hooks.module.js
  npm:plugin  preact -> npm/[email protected]/dist/preact.module.js
  npm:plugin  preact/hooks -> npm/[email protected]/hooks/dist/hooks.module.js
  npm:plugin  preact-render-to-string -> npm/[email protected]/dist/index.mjs
  npm:plugin  preact -> npm/[email protected]/dist/preact.module.js
(!) minify(index.d5d2e732.js) took 200ms

Merging assets/style.module.83820528.css into assets/style.module.7b16dcc3.css (chunks/index.fb97a71f.js → index.d5d2e732.js)
Hoisting CSS "assets/style.module.7b16dcc3.css" imported by index.d5d2e732.js into parent HTML import "assets/style.e6ee4bcf.css".

Wrote 23Kb to disk:
  dist/index.html 460b
  dist/index.d5d2e732.js 17Kb
  dist/assets/style.e6ee4bcf.css 499b
  dist/chunks/prerender.ea3dab95.js 4.8Kb
  dist/chunks/index.fb97a71f.js 214b
Segmentation fault: 11

zgoda avatar Nov 02 '21 16:11 zgoda

Downgraded node to v14.18.1 and everything works fine again.

zgoda avatar Nov 02 '21 16:11 zgoda

Just wanted to comment that I too encountered some bizarre segfaults with Node 16, though it was entirely inconsistent and would occur seemingly post-prerender?

Output would be generated just fine, but 50% of the time I'd be hit with a lovely SIGSEGV before completion. Rerunning the build nearly always completed without any error.

Downgraded back to Node 14 too, no issues here. Really weird.

Edit: No config from me, so shouldn't be related to that in any way. Will try to track this down when I have some time, could just be buggy Node I suppose?

rschristian avatar Nov 16 '21 03:11 rschristian

I've seen less of segfaults after upgrading npm to some later version, 8.1.2 or 8.1.3.

zgoda avatar Nov 16 '21 09:11 zgoda

Interesting. Yarn for me, though did have latest NPM (8.1.3).

rschristian avatar Nov 16 '21 17:11 rschristian

I think this is a duplicate issue: https://github.com/preactjs/wmr/issues/896#issuecomment-1004407280

I too am experiencing the random segmentation fault that prevents WMR prerender build from completing (missing HTML files in dist folder, and segfault in console). I am on MacOS, Node version 16.13.1, NPM version 8.3.0.

danielweck avatar Jan 03 '22 22:01 danielweck

...I should also point out that WMR config.middleware: [] doesn't yield 100% repro, it seems as random as config.middleware: undefined or config.middleware: null.

danielweck avatar Jan 03 '22 22:01 danielweck

Yes, it seems I was too quick assuming there's any relation.

zgoda avatar Jan 04 '22 17:01 zgoda

Should we close this as a duplicate of #896?

developit avatar Apr 12 '22 22:04 developit

I can reproduce this on wmr, 3.8.0 by just

yarn create wmr hello-preact-wmr
yarn build

It's 60-70% chance to get SIGSEGV (this one hit at first try, i'm feeling lucky)

katopz@fox hello-preact-wmr % yarn build
yarn run v1.22.17
$ wmr build --prerender

Wrote 27Kb to disk:
  dist/index.html 460b
  dist/index.32c06713.js 18Kb
  dist/assets/style.e6ee4bcf.css 499b
  dist/chunks/prerender.e1448b15.js 8.1Kb
  dist/chunks/index.08589ee3.js 214b
error Command failed with signal "SIGSEGV".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

katopz@fox hello-preact-wmr % node --version && npm --version
v16.13.0
8.5.0

Not sure what the root cause is.

katopz avatar Dec 10 '22 03:12 katopz