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

@swc/core-linux-x64-gnu v1.3.39-v1.3.40 segfaults with @vitejs/plugin-react-swc #7075

Closed
pakettiale opened this issue Mar 13, 2023 · 15 comments

Comments

@pakettiale
Copy link

pakettiale commented Mar 13, 2023

Describe the bug

Latest versions of SWC seems to segfault when bundling files for @vitejs/plugin-react-swc with linux-x64-gnu binary. Vite is running inside docker container based on node:18.13-bullseye.

Using segfault-handler library I get the following crash log.

PID 95 received SIGSEGV for address: 0x7f737d70618c
/develop/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x3236)[0x7f7924486236]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0xfe7379)[0x7f790e1e7379]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13140)[0x7f79279ab140]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x8ddf87)[0x7f790daddf87]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x8b8732)[0x7f790dab8732]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x8defc2)[0x7f790dadefc2]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0xa35180)[0x7f790dc35180]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0xa57be5)[0x7f790dc57be5]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x8df2fa)[0x7f790dadf2fa]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x8e29e1)[0x7f790dae29e1]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x9b8cfa)[0x7f790dbb8cfa]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x98e392)[0x7f790db8e392]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x89a6d5)[0x7f790da9a6d5]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x87cc74)[0x7f790da7cc74]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x8a1ddd)[0x7f790daa1ddd]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0xa2c3d3)[0x7f790dc2c3d3]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x81936a)[0x7f790da1936a]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x8ae12a)[0x7f790daae12a]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x8ae3cf)[0x7f790daae3cf]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0xa93118)[0x7f790dc93118]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x817c16)[0x7f790da17c16]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x816a58)[0x7f790da16a58]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x8116ca)[0x7f790da116ca]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x26d7f6)[0x7f790d46d7f6]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x25789c)[0x7f790d45789c]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x2bfcf1)[0x7f790d4bfcf1]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x256730)[0x7f790d456730]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x50e396)[0x7f790d70e396]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x53389f)[0x7f790d73389f]
/develop/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node(+0x2ef227)[0x7f790d4ef227]
node(_ZZN4node14ThreadPoolWork12ScheduleWorkEvENUlP9uv_work_sE_4_FUNES2_+0x5a)[0xb31b1a]
node[0x164da14]

Output from vite without segfault handler looks like this:

  VITE v4.1.4  ready in 611 ms

  ➜  Local:   http://localhost:8080/
  ➜  Network: http://172.18.0.5:8080/
Segmentation fault (core dumped)

Input code

No response

Config

@vitejs/plugin-react-swc does not seem to use any .swcrc files

Playground link

No response

Expected behavior

I expect the bundler to work correctly.

Actual behavior

It segfaults when I load the URL that vite is listening to.

Version

v1.3.39 and v1.3.40

Additional context

No response

@kdy1
Copy link
Member

kdy1 commented Mar 13, 2023

Can you provide a repro?

@pakettiale pakettiale changed the title @swc/core-linux-x64-gnu v1.3.40 segfaults with @vitejs/plugin-react-swc @swc/core-linux-x64-gnu v1.3.39-v1.3.40 segfaults with @vitejs/plugin-react-swc Mar 13, 2023
@pakettiale
Copy link
Author

I will see if I can produce a simple example

@kdy1 kdy1 added this to the Planned milestone Mar 13, 2023
@pakettiale
Copy link
Author

I couldn't reproduce this with vite's react-swc-ts template, starting to suspect that some other plugin or library we use is triggering the segfault.

@morlay
Copy link

morlay commented Mar 14, 2023

I got similar errors when I load my custom swc plugin https://github.com/innoai-tech/nodekit/tree/main/nodedevpkg/swc-plugin-annotate-pure-calls

@nodepkg/uikit:build: [@nodepkg/uikit] bundling (target: {"safari":"15.6","firefox":"102","edge":"109","chrome":"108"})
@nodepkg/uikit:build: thread '<unnamed>' panicked at 'failed to invoke plugin: failed to invoke plugin on 'None'
@nodepkg/uikit:build: 
@nodepkg/uikit:build: Caused by:
@nodepkg/uikit:build:     0: RuntimeError: out of bounds memory access
@nodepkg/uikit:build:     1: heap_get_oob', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/swc-0.255.3/src/plugin.rs:228:14
@nodepkg/uikit:build: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@nodepkg/uikit:build: Segmentation fault (core dumped)

Everything works fine out of docker container.
But once run in docker container, it will be broken.

Btw. it work well in node (18 or 19) container for linux/arm64 (OS: Ubuntu 18.04 4.15.0-70-generic).

For linux/amd64,
it works well in github actions with Ubuntu 22.04 (5.15),
But failed in my build env, with Ubuntu 18.04 (4.15.0-70-generic)

@pakettiale Which OS you docker running? It may some issue caused by linux kernal.

@kdy1 bacause of #6807,
I build the plugin wasm with rust@nightly-2022-09-27,
not sure is it cause this issue?

@kdy1
Copy link
Member

kdy1 commented Mar 14, 2023

What the...
So... the error depends on glibc or kernel?
cc @Brooooooklyn @kwonoj Any ideas?

@kdy1
Copy link
Member

kdy1 commented Mar 14, 2023

If it's a miscompilation for linux-x86_64 target, both of Ubuntu 22.04 (5.15) and Ubuntu 18.04 (4.15.0-70-generic) should fail, I think

@morlay
Copy link

morlay commented Mar 14, 2023

Ubuntu 18.04 already upgrade to kernel 5.4.0 on Github Actions, both works well.
https://github.com/morlay/swc-issue-7075/actions/runs/4416545030

So I have to print the output in my Ubuntu 18.04 (4.15.0-70-generic) with the simple usage
https://github.com/morlay/swc-issue-7075

~/swc-issue-7075-main $ uname -mr
4.15.0-70-generic aarch64
~/swc-issue-7075-main $ RUST_BACKTRACE=1 npx tsx index.ts
thread '<unnamed>' panicked at 'failed to invoke plugin: failed to invoke plugin on 'None'

Caused by:
    0: Cannot compile plugin binary
    1: Validation error: Unexpected EOF (at offset 1441596)

Stack backtrace:
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>
  15: <unknown>
  16: <unknown>
  17: <unknown>
  18: <unknown>
  19: <unknown>
  20: _ZZN4node14ThreadPoolWork12ScheduleWorkEvENUlP9uv_work_sE_4_FUNES2_
  21: worker
             at /node-v18.13.0/out/../deps/uv/src/threadpool.c:122:5
  22: <unknown>', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/swc-0.255.3/src/plugin.rs:228:14
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Error: failed to handle: failed to invoke plugin: failed to invoke plugin on 'None'

Caused by:
    0: Cannot compile plugin binary
    1: Validation error: Unexpected EOF (at offset 1441596)

Stack backtrace:
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>
  15: <unknown>
  16: <unknown>
  17: <unknown>
  18: <unknown>
  19: <unknown>
  20: _ZZN4node14ThreadPoolWork12ScheduleWorkEvENUlP9uv_work_sE_4_FUNES2_
  21: worker
             at /node-v18.13.0/out/../deps/uv/src/threadpool.c:122:5
  22: <unknown>

Stack backtrace:
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: _ZZN4node14ThreadPoolWork12ScheduleWorkEvENUlP9uv_work_sE_4_FUNES2_
   9: worker
             at /node-v18.13.0/out/../deps/uv/src/threadpool.c:122:5
  10: <unknown>] {
  code: 'GenericFailure'
}

Node.js v18.13.0

One more interesting thing:
Node 16 on Ubuntu 18.04 with kernel 4.15.0-70-generic works well 🤣

@kdy1 confirmed,
it only broken on Ubuntu 18.04 with kernel 4.15.0-70-generic with Node 18+ in my hosts

@pakettiale
Copy link
Author

@morlay I'm running on container based on Debian 11

https://hub.docker.com/layers/library/node/18.13-bullseye/images/sha256-d9061fd0205c20cd47f70bdc879a7a84fb472b822d3ad3158aeef40698d2ce36?context=explore

Container uses the current host kernel (archlinux 6.2.6-arch1-1) but this happened also on previous kernel 6.1.x.

Container glibc

$ ldd --version
ldd (Debian GLIBC 2.31-13+deb11u5) 2.31

@morlay
Copy link

morlay commented Mar 14, 2023

Container uses the current host kernel (archlinux 6.2.6-arch1-1) but this happened also on previous kernel 6.1.x.

Kernel issue ... terrible 🙀

@pakettiale
Copy link
Author

For the record we are using @lingui/swc-plugin. Disabling this plugin allows vite/swc to bundle and serve files to the browser. Of course the source is broken because lingui tokens are not processed but I no longer get segfault with swc.

@Brooooooklyn
Copy link
Member

In the stacktrace from @morlay:

Caused by:
    0: Cannot compile plugin binary
    1: Validation error: Unexpected EOF (at offset 1441596)

Stack backtrace:
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>
  15: <unknown>
  16: <unknown>
  17: <unknown>
  18: <unknown>
  19: <unknown>
  20: _ZZN4node14ThreadPoolWork12ScheduleWorkEvENUlP9uv_work_sE_4_FUNES2_
  21: worker
             at /node-v18.13.0/out/../deps/uv/src/threadpool.c:122:5
  22: <unknown>', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/swc-0.255.3/src/plugin.rs:228:14
stack backtrace:

It seems like the wasmer crash in Node.js worker_threads.

@Brooooooklyn
Copy link
Member

Maybe related: wasmerio/wasmer#3526

@timofei-iatsenko
Copy link

For the record we are using @lingui/swc-plugin. Disabling this plugin allows vite/swc to bundle and serve files to the browser.

i'm the author of this plugin, is there something what i can do from my side? Or it's completely unrelated to plugin itself?
Maybe build with other swc_core or rust version?

@kdy1
Copy link
Member

kdy1 commented Mar 31, 2023

Closing as #6807 is fixed

@kdy1 kdy1 closed this as completed Mar 31, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.44 Mar 31, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Apr 30, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Apr 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

6 participants