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

Segmentation fault when calling uv_os_getenv from a native addon #47416

Closed
andreasciamanna opened this issue Apr 5, 2023 · 4 comments
Closed

Comments

@andreasciamanna
Copy link

Version

v18.15.0

Platform

5.19.0-38-generic #39-Ubuntu SMP PREEMPT_DYNAMIC x86_64 x86_64 x86_64 GNU/Linux

Subsystem

getenv (?)

What steps will reproduce the bug?

Please let me know if this is the right place to report this issue.

I'm facing an intermittent segmentation fault (SIGSEGV) when my NestJS application tries to retrieve environment variables (I suspect: see below).

The error appears when the NestJS triggers an incremental compilation due to changes in the code.
So far, this is the only scenario that can be easily fixed by stopping and restarting the local environment.
I could not see the issue in production.

To try to get some more information about the error, I've installed segfault-handler as suggested here and got the following:

PID 1519688 received SIGSEGV for address: 0x7f35e0a53
/{MASKED}/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x372d)[0x7f35e0fa772d]
/lib/x86_64-linux-gnu/libc.so.6(+0x3bcf0)[0x7f35e083bcf0]
/lib/x86_64-linux-gnu/libc.so.6(getenv+0xad)[0x7f35e083f25d]
node(uv_os_getenv+0x31)[0x166d1c1]
node(_ZNK4node12RealEnvStore5QueryEPN2v87IsolateENS1_5LocalINS1_6StringEEE+0x4c)[0xb7805c]
node[0xb7877e]
node[0x1147f86]
node[0x12d8108]
node(_ZN2v88internal24Runtime_ForInHasPropertyEiPmPNS0_7IsolateE+0x31)[0x12d8431]
node[0x1707b79]

With this package running, the SEGFAULT happens at every start of the app.
However, once I commented out the call to SegfaultHandler.registerHandler('crash.log');, the SEGFAULT resumed being intermittent.

A bit of googling seems to bring more or less this:

The error occurs when the addon calls the getenv function from the C standard library with an invalid argument, causing it to crash with a segmentation fault.

I'm not 100% sure if the culprit is getenv or if this is a core module, but I suspect it is.

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

So far, it appears only after a not-known number of incremental compilations from NestJS (npm run start:dev).

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

No response

What do you see instead?

segmentation fault (core dumped)

Additional information

No response

@bnoordhuis
Copy link
Member

My guess is you have a non-zero number of native add-ons installed. What does find node_modules -name \*.node print? Try excluding those.

@andreasciamanna
Copy link
Author

My guess is you have a non-zero number of native add-ons installed. What does find node_modules -name \*.node print? Try excluding those.

node_modules/.prisma/client/libquery_engine-debian-openssl-3.0.x.so.node
node_modules/prisma/libquery_engine-debian-openssl-3.0.x.so.node
node_modules/@prisma/engines/libquery_engine-debian-openssl-3.0.x.so.node

npm rebuild does not help, and I can't exclude them: I need them from my project to work.

However, as the error seem to be caused by the native add-on, I wonder how they are involved with the error.

@andreasciamanna
Copy link
Author

Well, there seems to be an open and related issue after all.

I'll try what's suggested there and come back here with the results.

@bnoordhuis
Copy link
Member

We don't accept bug reports that involve native add-ons because 9 out of 10 times (mild understatement) the bug is inside the add-on and not node.

I'll go ahead and close this but let me know if it still happens without those add-ons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants