nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.13k stars 28.87k forks source link

v22.4.1 C++ addon incurs segmentation faults #53810

Open tvmoo9 opened 1 month ago

tvmoo9 commented 1 month ago

Version

v22.4.1

Platform

Linux Debian 6.1.0-22-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.94-1 (2024-06-21) x86_64 GNU/Linux

Subsystem

node-addon-api

What steps will reproduce the bug?

Run a simple hello-world C++ wrapper addon test by following https://www.npmjs.com/package/generator-napi-module, it returns "segmentation faults" runtime error; there is no such an error for v20.15.1 and v20.14.0 which are only other two versions tested.

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

Every time

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

No runtime error

What do you see instead?

Segmentation faults

Additional information

No response

RedYetiDev commented 1 month ago

Hi! Thanks for the report!

If you don't mind, it'd be a bit easier to understand if you did the following:

Thank you!

tvmoo9 commented 1 month ago

Hi, I uninstalled v22.4.1 after fully switched to v20.15.1 LTS. Below is the simple code that can reproduce aforementioned "segmentation faults" on v22.4.1. All my other C++ addons have the same memory fault on v22.4.1.

On native C++ side:

#include <napi.h>

using namespace Napi;

Napi::String TestFunc(const Napi::CallbackInfo& info) {
  Napi::Env env = info.Env();
  return Napi::String::New(env, "Successful");
}

Napi::Object Init(Napi::Env env, Napi::Object exports) {
  exports.Set(Napi::String::New(env, "TestFunc"),
              Napi::Function::New(env, TestFunc));
  return exports;
}

NODE_API_MODULE(addon, Init)

On Nodejs side:

const addon = require('../build/Release/test-native');
console.log(addon.TestFunc());

Thanks.

RedYetiDev commented 1 month ago

Thanks! I've pinged the relevant teams.

Are you following the instructions at https://nodejs.org/docs/latest/api/addons.html to build the addon?


Ping @nodejs/node-api


(To members) should this be here, or nodejs/help?

tvmoo9 commented 1 month ago

Thanks! I've pinged the relevant teams.

Are you following the instructions at https://nodejs.org/docs/latest/api/addons.html to build the addon?

Ping @nodejs/node-api

(To members) should this be here, or nodejs/help?

I thinks I did.

legendecas commented 1 month ago

Doesn't seem to be reproducible on mac. Might be a linux only problem. Would you mind sharing more information about the crash, like backtrace?

santigimeno commented 1 month ago

Can't reproduce on linux either

mhdawson commented 2 weeks ago

@tvmoo9 just wondering if you are still facing the issue. Since it's not reproduciable by the node-api team we'll close unless we hear back from you in the next week.

mhdawson commented 2 weeks ago

@tvmoo9, can you share which version of Debian you were running on as we can't tell that from the info shared so far.

tvmoo9 commented 1 week ago

@tvmoo9, can you share which version of Debian you were running on as we can't tell that from the info shared so far.

The Debian version is 12.6 which has this issue. The same code has no problem with Ubuntu 24.04. No other Linux distributions tested so far.