Skip to content

node 20 segfaults when our loader runs #50280

Closed as not planned
Closed as not planned
@bmacnaughton

Description

Version

v20.8.0

Platform

Linux wsl 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

module loaders

What steps will reproduce the bug?

Unfortunately, I am unable to reproduce this in a simple application; I have spent a lot of time trying to do so but am obviously missing something. I'll try to explain what I see.

we execute as a loader, node --loader our-loader user-application.

Prior to node 20, the loaders ran in the same thread as main. Our-loader initializes "data", which includes functions, in global. It then transforms user-application such that the "data" in global is referenced. Because the loader thread does not share global with the main thread, an error is thrown when referencing properties in "data". (This is easily reproducible, but I have not been able to create a small test case that reproduces the segfault.)

The "SyntaxError" that is thrown is our check to verify that the required "data" is in global. If I fake up "data" using globalPreload or register(), it will get past this check but will die when "data" is really needed.

How often does it reproduce? Is there a required condition?

Every time on node 20.0+

What is the expected behavior? Why is that the expected behavior?

No segfault.

What do you see instead?

 node --loader ./dist/esm-loader.mjs  test/_servers/express.mjs
(node:24127) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:24127) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
[--loader load() hook: test/_servers/express.mjs, module, id: 1]
(node:24127) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
[--loader load() hook: node:child_process, builtin, id: 1]
[--loader load() hook: node:fs, builtin, id: 1]
file:///patch-thing/test/_servers/express.mjs:3
  throw new SyntaxError("data undefined during compilation");
        ^

SyntaxError: data undefined during compilation
    at file:///patch-thing/test/_servers/express.mjs:3:9
    at file:///patch-thing/test/_servers/express.mjs:4:3
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)

Node.js v20.0.0
Segmentation fault

Additional information

I submitted this not-very-good bug report because I've wrestled with this for a while now and have not been able to create a simple test case. The fact that it segfaults led me to submit this anyway with the hopes that someone that's been working on this can say "ok, this is the problem".

I have tried using --import rather than --loader and get the same result. I'm working on changing our code to use register() but doesn't seem likely to address the issue of global not being available in a worker-thread.

I am very interested in any suggestions on how to handle this. Maybe we need to start forcing import and/or require into the transformed user-application in order to reproduce global? We've tried to avoid that but maybe it's no longer possible.

Metadata

Assignees

No one assigned

    Labels

    addonsIssues and PRs related to native addons.loadersIssues and PRs related to ES module loaders

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions