-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Maglev on x64 causes segmentation fault while running TypeScript #52797
Comments
Hi! Could you possibly provide some example code to reproduce this? Preferably code that has been compiled into plain JS. |
I would absolutely love to. Unfortunately the bug is reproduced by running It was caused by microsoft/TypeScript#53081 and fixed by microsoft/TypeScript#58339 (unreleased yet). |
AFAICT this doesn't seem like an issue with Node.js itself, but rather a compiler (such as |
Sorry, I now see I forgot to provide a critical piece of information. This is a regression in Node.js 22.0.0. It wasn’t a problem before. |
Ahh, okay, thank you. |
@targos I have a feel we rushed the V8 upgrades. cc @nodejs/v8 @RafaelGSS |
It's probably related to V8, but I'm not sure waiting would have changed anything? We released v22.0.0 with the version of V8 that's in current Chrome. |
Seems specific to Linux or x64 as I cannot reproduce on ARM64 macOS. |
We also don't know which version of V8 introduced the bug (assuming it's in V8). |
So, it's specific to x64. I can reproduce with |
I'm going to compile a debug build on one of the Hetzner machines to get a meaningful stack trace. |
I’m on macOS and repro it consistently btw |
@woorm ARM or Intel? |
The code that started/stopped crashing in TS had do to with indexing into strings. One TS maintainer potentially saw the crash appear/disappear when adding a |
I’m on an 2.6 GHz 6-Core Intel Core i7, Sonoma 14.4.1 (23E224). |
Ignore the repro-exists tag, I didn't mean to add it, and it won't effect anything. |
Just to give a side by side using https://github.com/remcohaszing/typescript-bug-58369: $ grep -A8 'function scanJSDocCommentTextToken' ./node_modules/typescript/lib/tsc.js
function scanJSDocCommentTextToken(inBackticks) {
fullStartPos = tokenStart = pos;
tokenFlags = 0 /* None */;
if (pos >= end) {
return token = 1 /* EndOfFileToken */;
}
for (let ch = text.charCodeAt(pos); pos < end && (!isLineBreak(ch) && ch !== 96 /* backtick */); ch = codePointAt(text, ++pos)) {
if (!inBackticks) {
if (ch === 123 /* openBrace */) {
$ node ./node_modules/typescript/lib/tsc.js
[1] 1090384 segmentation fault node ./node_modules/typescript/lib/tsc.js Now, add $ grep -A8 'function scanJSDocCommentTextToken' ./node_modules/typescript/lib/tsc.js
function scanJSDocCommentTextToken(inBackticks) {
fullStartPos = tokenStart = pos;
tokenFlags = 0 /* None */;
if (pos >= end) {
return token = 1 /* EndOfFileToken */;
}
for (let ch = text.charCodeAt(pos); pos < end && (!isLineBreak(ch) && ch !== 96 /* backtick */); ch = codePointAt(text, ++pos)) {
debugger; // ADDED
if (!inBackticks) {
$ node ./node_modules/typescript/lib/tsc.js I have not been able to extract out a test which just calls the parser via the public API, nor by extracting this code and giving it the same inputs. |
Weird, thanks for the information! |
Perfect 🙃 |
Just to note it, you can also add |
The original issue is TypeScript processing |
This is a workaround for nodejs/node#52797.
Related-to: DefinitelyTyped/DefinitelyTyped#69584. Related-to: microsoft/TypeScript#58369. Related-to: nodejs/node#52797.
Given that there hasn't been any activity here in a while or on the V8 tracker at all--is there any appetite for reverting Maglev being on by default? Maybe this is an overreaction to Node 22 constantly segfaulting on my desktop, but as-is I wouldn't feel comfortable putting it in production. It would be different if I could just put |
There's some nasty segfault being dealt with upstream in node itself. Until that gets fixed, lets use 20.x. Issue can be tracked here: nodejs/node#52797
There's some nasty segfault being dealt with upstream in node itself. Until that gets fixed, lets use 20.x. Issue can be tracked here: nodejs/node#52797
FYI this issue with maglev inlining also affects Node 22. With this issue there's no segfault, but the JS doesn't do what it's supposed to.
|
Apparently there seem to be backport available for the latter. @nodejs/v8 are we planning an update of v8 before we hit LTS? |
A full V8 update in v22 is very unlikely (too many breaking changes in the C++ API) |
Looking at the related bugs I think we should disable maglev by default for v22, considering it will get stuck with V8 12.4 for ~2 years, and it will probably be increasingly difficult to backport any maglev patches to it even if they get fixed in the upstream. We could continue enabling it on the main branch and maybe consider enabling it in v23 to test it out, but it doesn't look great to ship the crashes to LTS. |
It seems the safest approach, considering that there isn't really much we can do. |
It needs a handle scope for the context handle. Since the FastApiCallbackOptions struct doesn't have isolate on it in V8 12.4 on Node.js 22, use Isolate::TryGetCurrent() to get to the isolate needed for the handle scope creation and fallback to the slow callback if no isolate is entered. PR-URL: #54384 Refs: #52797 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This reverts commit 1a5acd0. Reason to revert: we have seen several crashes/unexpected JS behaviors with maglev on v22 (which ships V8 v12.4). The bugs lie in the codegen so it would be difficult for users to work around them or even figure out where the bugs are coming from. Some bugs are fixed in the upstream while some others probably remain. As v22 will get stuck with V8 v12.4 as LTS, it will be increasingly difficult to backport patches for them even if the bugs are fixed. So disable it by default on v22 to reduce the churn and troubles for users. PR-URL: #54384 Refs: #52797 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Maglev was disabled on v22.x with #54384 |
It's still enabled on main, right? So it's still not fixed until V8 is fixed? |
Do we know that this issue also affects |
BTW on the V8 slack @deepak1556 mentioned that they were able to reproduce it in Electron with v8 12.4 and 12.6 but not 12.8 so it's likely fixed. |
Yup the repro mentioned in this post can be run with Simple bisect of our prebuilt binaries showed, first good version is Here is the chromium changelist url https://chromium.googlesource.com/chromium/src/+log/127.0.6521.0..128.0.6571.0?n=10000&pretty=fuller and V8 changelist https://chromium.googlesource.com/v8/v8/+log/12.7.189..12.8.185?n=10000&pretty=fuller |
Version
v22.0.0
Platform
Linux vali 6.8.0-76060800daily20240311-generic #202403110203
171407766522.04~4c8e9a0 SMP PREEMPT_DYNAMIC Thu A x86_64 x86_64 x86_64 GNU/LinuxSubsystem
No response
What steps will reproduce the bug?
On Linux using Node.js 22:
git clone git@github.com:remcohaszing/typescript-bug-58369.git cd typescript-bug-58369 npm ci tsc
See also this failed GitHub action: https://github.com/remcohaszing/typescript-bug-58369/actions/runs/8899456400/job/24438867767
How often does it reproduce? Is there a required condition?
For this reproduction it’s reproduced consistently on Linux on both my machine and GitHub actions.
While troubleshooting by trimming down the content of
node_modules/@types/mdast/index.d.ts
, I got into a state where it seemed to happen randomly. The major factor is the👉
emoji in a comment.The error did not occur on macOS in the GitHub action, but it did happen consistently for @wooorm on their macbook.
The problem was not reproducible on Windows.
What is the expected behavior? Why is that the expected behavior?
No segmentation fault
What do you see instead?
Additional information
This was originally reported to TypeScript: microsoft/TypeScript#58369. This issue contains more information.
This has coincidentally already been fixed for the upcoming TypeScript 5.5. Still, a segfault should not occur.
We were unable to make a smaller reproduction.
The text was updated successfully, but these errors were encountered: