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

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

Closed
1 of 3 tasks
zgoda opened this issue Oct 31, 2021 · 13 comments
Closed
1 of 3 tasks
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@zgoda
Copy link

zgoda commented Oct 31, 2021

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)
  • 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 zgoda added the bug Something isn't working label Oct 31, 2021
@rschristian
Copy link
Member

Can you provide the error please?

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

@zgoda
Copy link
Author

zgoda commented Nov 2, 2021

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.

@rschristian
Copy link
Member

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

@zgoda
Copy link
Author

zgoda commented Nov 2, 2021

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
Copy link
Author

zgoda commented Nov 2, 2021

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

@zgoda zgoda changed the title Build segfaults if config contains empty middleware array Build segfaults on Node.js v16 if config contains empty middleware array Nov 2, 2021
@rschristian
Copy link
Member

rschristian commented Nov 16, 2021

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?

@zgoda
Copy link
Author

zgoda commented Nov 16, 2021

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

@rschristian
Copy link
Member

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

@danielweck
Copy link

I think this is a duplicate issue: #896 (comment)

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
Copy link

...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.

@zgoda
Copy link
Author

zgoda commented Jan 4, 2022

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

@developit
Copy link
Member

Should we close this as a duplicate of #896?

@developit developit added the duplicate This issue or pull request already exists label Apr 12, 2022
@katopz
Copy link

katopz commented Dec 10, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

5 participants