Using Node.js 20, rake npm:ruby-head-wasm-wasi:check does not work
What happened.
I installed Node.js 20.8.0 and ran rake npm:ruby-head-wasm-wasi:check and got the following error:
►rake npm:ruby-head-wasm-wasi:check
npm test
> [email protected] test
> RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasi npm -C ../ruby-wasm-wasi run test:run
> @ruby/[email protected] test:run
> npm run test:unit && npm run test:jest && npm run test:e2e
> @ruby/[email protected] test:unit
> ./tools/run-test-unit.mjs
(node:66391) ExperimentalWarning: WASI is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/errors:497
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "options.version" property must be of type string. Received undefined
at new NodeError (node:internal/errors:406:5)
at validateString (node:internal/validators:162:11)
at new WASI (node:wasi:51:5)
at instantiateNodeWasi (file:///home/ledsun/ruby.wasm/packages/npm-packages/ruby-wasm-wasi/tools/run-test-unit.mjs:30:16)
at async test (file:///home/ledsun/ruby.wasm/packages/npm-packages/ruby-wasm-wasi/tools/run-test-unit.mjs:128:24)
at async main (file:///home/ledsun/ruby.wasm/packages/npm-packages/ruby-wasm-wasi/tools/run-test-unit.mjs:162:3) {
code: 'ERR_INVALID_ARG_TYPE'
}
Node.js v20.8.0
npm ERR! Lifecycle script `test:unit` failed with error:
npm ERR! Error: command failed
npm ERR! in workspace: @ruby/[email protected]
npm ERR! at location: /home/ledsun/ruby.wasm/packages/npm-packages/ruby-wasm-wasi
npm ERR! Lifecycle script `test` failed with error:
npm ERR! Error: command failed
npm ERR! in workspace: [email protected]
npm ERR! at location: /home/ledsun/ruby.wasm/packages/npm-packages/ruby-head-wasm-wasi
rake aborted!
Command failed with status (1): [npm test]
/home/ledsun/ruby.wasm/tasks/packaging.rake:21:in `block (4 levels) in <top (required)>'
Tasks: TOP => npm:ruby-head-wasm-wasi:check
(See full trace by running task with --trace)
It worked fine using Node.js 18.8.2.
What I tried
Added version property to the argument of the WASI constructor.
https://github.com/ruby/ruby.wasm/blob/5a28621732af565f888648da5bdd1f3fc6fd398e/packages/npm-packages/ruby-wasm-wasi/tools/run-test-unit.mjs#L30-L39
I have tried both unstable and preview1 according to https://nodejs.org/docs/latest-v20.x/api/wasi.html.
The test ended with a Segmentation fault.
ledsun@MSI:~/ruby.wasm►rake npm:ruby-head-wasm-wasi:check
npm test
> [email protected] test
> RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasi npm -C ../ruby-wasm-wasi run test:run
> @ruby/[email protected] test:run
> npm run test:unit && npm run test:jest && npm run test:e2e
> @ruby/[email protected] test:unit
> ./tools/run-test-unit.mjs
(node:68755) ExperimentalWarning: WASI is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Ignoring debug-1.8.0 because its extensions are not built. Try: gem pristine debug --version 1.8.0
Ignoring racc-1.7.3 because its extensions are not built. Try: gem pristine racc --version 1.7.3
Ignoring rbs-3.3.2 because its extensions are not built. Try: gem pristine rbs --version 3.3.2
Loaded suite /__root__/test/test_unit
Started
Segmentation fault
npm ERR! Lifecycle script `test:unit` failed with error:
npm ERR! Error: command failed
npm ERR! in workspace: @ruby/[email protected]
npm ERR! at location: /home/ledsun/ruby.wasm/packages/npm-packages/ruby-wasm-wasi
npm ERR! Lifecycle script `test` failed with error:
npm ERR! Error: command failed
npm ERR! in workspace: [email protected]
npm ERR! at location: /home/ledsun/ruby.wasm/packages/npm-packages/ruby-head-wasm-wasi
rake aborted!
Command failed with status (1): [npm test]
/home/ledsun/ruby.wasm/tasks/packaging.rake:21:in `block (4 levels) in <top (required)>'
Tasks: TOP => npm:ruby-head-wasm-wasi:check
(See full trace by running task with --trace)
From my bisect, it looks like there should be something wrong in Node.js v19.3.0...v19.4.0.
Here is the detailed backtrace for the segmentation fault.
$ RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasi ./tools/run-test-unit.mjs
(node:3296220) ExperimentalWarning: WASI is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
#
# Fatal error in , line 0
# unreachable code
#
#
#
#FailureMessage Object: 0x7ffd18712500
1: 0xd15331 [node]
2: 0x20ef531 V8_Fatal(char const*, ...) [node]
3: 0x1120796 v8::internal::MarkCompactCollector::ProcessMarkingWorklist(unsigned long, v8::internal::MarkCompactCollector::MarkingWorklistProcessingMode) [node]
4: 0x11231f2 v8::internal::MarkCompactCollector::ProcessEphemerons() [node]
5: 0x11234a9 v8::internal::MarkCompactCollector::MarkTransitiveClosureUntilFixpoint() [node]
6: 0x11243e8 v8::internal::MarkCompactCollector::MarkTransitiveClosure() [node]
7: 0x112f996 v8::internal::MarkCompactCollector::MarkLiveObjects() [node]
8: 0x11343d2 v8::internal::MarkCompactCollector::CollectGarbage() [node]
9: 0x10e2306 v8::internal::Heap::MarkCompact() [node]
10: 0x10e795d v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*) [node]
11: 0x10e7e4c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
12: 0x10e8b6a v8::internal::Heap::FinalizeIncrementalMarkingIfComplete(v8::internal::GarbageCollectionReason) [node]
13: 0x10e8747 v8::internal::Heap::ReportExternalMemoryPressure() [node]
14: 0xed6be2 v8::Isolate::AdjustAmountOfExternalAllocatedMemory(long) [node]
15: 0x123ccca v8::internal::BackingStore::GrowWasmMemoryInPlace(v8::internal::Isolate*, unsigned long, unsigned long) [node]
16: 0x17a64d0 v8::internal::WasmMemoryObject::Grow(v8::internal::Isolate*, v8::internal::Handle<v8::internal::WasmMemoryObject>, unsigned int) [node]
17: 0x1633aeb v8::internal::Runtime_WasmMemoryGrow(int, unsigned long*, v8::internal::Isolate*) [node]
18: 0x1930ef6 [node]
zsh: trace trap RUBY_NPM_PACKAGE_ROOT=../ruby-head-wasm-wasi ./tools/run-test-unit.mjs
I can confirm this doesn't work with Node.js 21 either. By the way, the fix to https://github.com/ruby/ruby.wasm/blob/main/packages/npm-packages/ruby-wasm-wasi/tools/run-test-unit.mjs#L30 (adding { version: "preview1" }) can be done independently of that. Should I send a PR?
@terrablue Yes, that would be helpful :)
@kateinoigakukun is it possible to run at least part of the tests or isolate this problem down to a particular test? I would like to start contributing, but it's hard to know if I'm introducing regressions otherwise.
I think the easiest way at this time is just using Node.js older than 19. Or you can find how to execute a part of test suites by checking rake outputs.
we are using node 20 LTS in production.
I suspect https://github.com/nodejs/node/pull/43697/ includes something wrong