question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Segmentation fault / std::bad_alloc on node version >= v12

See original GitHub issue

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Ubuntu 20.04, Debian Buster, OSX 10.15.6, Alpine 3.12.0
  • Firebase SDK version: 9.2.0
  • Firebase Product: database
  • Node.js version: v12.18.3
  • NPM version: 6.14.6

[REQUIRED] Step 3: Describe the problem

We have a pretty basic js-script to update a property in firebase (see below). This script works fine on node v10 and v11 but has a segmentation fault (std::bad_alloc) when run on node v12 or higher

Steps to reproduce:

Switch node version and run script:

$ nvm use v10
Now using node v10.22.1 (npm v6.14.6)

$ time node fire.js
OK
node fire.js  0,30s user 0,04s system 26% cpu 1,249 total


$ nvm use v12
Now using node v12.18.3 (npm v6.14.6)

$ time node ./fire.js 
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
[2]    3460141 abort (core dumped)  node ./fire.js
node ./fire.js  0,28s user 0,03s system 0% cpu 1:01,63 total

(note the 28 second duration)

$ nvm use v14
Now using node v14.12.0 (npm v6.14.8)

$ time node fire.js
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
[2]    3456469 abort (core dumped)  node fire.js
node fire.js  0,25s user 0,02s system 26% cpu 1,039 total

Relevant Code:

const admin = require('firebase-admin');
const FIREBASE_AUTH_DOMAIN = '';
const FIREBASE_DATABASE_URL = '';
const FIREBASE_CLIENT_EMAIL = '';
const FIREBASE_PRIVATE_KEY = ''

const credential = admin.credential.cert({
    projectId: FIREBASE_AUTH_DOMAIN,
    clientEmail: FIREBASE_CLIENT_EMAIL,
    privateKey: FIREBASE_PRIVATE_KEY,
});

const app = admin.initializeApp(
    {
        credential,
        databaseURL: FIREBASE_DATABASE_URL,
    },
    FIREBASE_AUTH_DOMAIN,
);
const firebaseScreenData = {
    'some-prop': 'some-value',
};
const firebaseClient = app;
const database = firebaseClient.database();

const main = async () => {
    try {
        await database.ref('temp-db').set(firebaseScreenData);
        await firebaseClient.delete();
    } catch (e) {
        console.log('Error', e);
        throw e;
    }
    console.log('OK');
};

main();

Node versions tested:

Version Works
v8.11.4
v10.22.1
v11.15.0
v12.18.3
v13.14.0
v14.12.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:12
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
Cyril-Beeckmancommented, Dec 23, 2020

Same issue.

Running Firebase Admin on NodeJS > 11.15.0 cause “std::bad_alloc” or “Segmentation fault”

Node version : 14.6.0 Firebase Admin version : 9.4.2

Capture

Everything works well with Node v11.15.0 and firebase-admin@9.4.2

2reactions
Kamshakcommented, Sep 29, 2020

Getting the same on a simple read with a query

const trips = Object.values<any>(
    (
      await app
        .database()
        .ref('trips')
        .orderByChild('type')
        .equalTo('trip')
        .limitToFirst(100)
        .once('value')
    ).val()
  );
PID 6554 received SIGSEGV for address: 0x0
/home/valentin/frantz2/ssr/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x3246)[0x7f13bcbac246]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13510)[0x7f13bf58d510]
/lib/x86_64-linux-gnu/libc.so.6(+0x15f3b5)[0x7f13bf5193b5]
/home/valentin/.nvm/versions/node/v12.18.2/bin/node[0xa2a80d]
/home/valentin/.nvm/versions/node/v12.18.2/bin/node[0xbee089]
/home/valentin/.nvm/versions/node/v12.18.2/bin/node(_ZN2v88internal21Builtin_HandleApiCallEiPmPNS0_7IsolateE+0xb7)[0xbefe77]
/home/valentin/.nvm/versions/node/v12.18.2/bin/node[0x13ccf79]
valentin@LAPTOP-IU1DQOIA:~/frantz2/ssr$ node --version
v12.18.2
valentin@LAPTOP-IU1DQOIA:~/frantz2/ssr$ uname -r
4.19.128-microsoft-standard
Read more comments on GitHub >

github_iconTop Results From Across the Web

node Segmentation fault on version change - Stack Overflow
When we type n the versions we installed show up but they are all greyed out. What's a Segmentation fault, why is it...
Read more >
Installing node.js on v1 Model B - segmentation fault
newbie here. Raspberry Pi 1 Model B. Raspbian. Had Adafruit WebIDE before. pi@raspberrypi ~ $ node -v Segmentation fault. tried to uninstall:
Read more >
The request for the fix and improvement of Node.js modules or ...
prompting a message “Segmentation fault (core dumped)”. But it is success to be running at cv::FileStorage.open() in Node.js version v12.18.2.
Read more >
Core Dump (Segmentation fault) in C/C++ - GeeksforGeeks
It is an error indicating memory corruption. Common segmentation fault scenarios: Modifying a string literal : The below program may crash ( ...
Read more >
IV79436: SEGMENTATION FAULT IN BASIC_STRING CODE ...
13 compiler or earlier encounters runtime segmentation faults after upgrading to the XL C++ Runtime, V13.1 (fileset: xlC.rte). The XL C++ Runtime, V12.1...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found