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

Created on 24 Sep 2020  ·  15Comments  ·  Source: firebase/firebase-admin-node

[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 | ❌ |

database

Most helpful comment

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 [email protected]

All 15 comments

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

@schmidt-sebastian @Feiyang1 are there any known issues for RTDB on Node12?

I can take a look at this next week.

Just made a preliminary attempt to repro the issue using the given code sample and Node12, but it worked fine:

const admin = require('firebase-admin');

const app = admin.initializeApp({
  credential: admin.credential.applicationDefault(),
  databaseURL: 'https://********.firebaseio.com',
});
const database = admin.database();

const main = async () => {
  try {
    await database.ref('temp-db').set({foo: `timestamp-${Date.now()}`});
    await app.delete();
  } catch (e) {
    console.log('Error', e);
    throw e;
  }

  console.log('OK');
};

main();
$ node --version
v12.18.4
$ node rtdb.js
OK

I had this issue, but running yarn upgrade fixed it
So i believe it's related to a sub dep, or combination of sub deps

@Bnaya Thanks for letting us know.
@filidorwiese Can you confirm that you are using the newest versions of all dependencies?

Having the same issue.
Node version: 12.18.3
Firebase-admin version: 9.2.0

Did exactly as the documentation said.

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 [email protected]

Unfortunately it's a blocking issue for me, I can't use Node < 12
Is there a workaround for the issue?

Unfortunately it's a blocking issue for me, I can't use Node < 12
Is there a workaround for the issue?

You could potentially try and earlier release of Firebase? Not ideal, but you might get lucky and find this bug was introduced recently enough that it doesn't cause breaking changes.

I am also not able to reproduce on v12.18.3 or v12.18.4.

For lack of better options, have you tried one of the suggestions here: https://stackoverflow.com/questions/38558989/node-js-heap-out-of-memory/59923848#59923848 ?

I am also not able to reproduce on v12.18.3 or v12.18.4.

For lack of better options, have you tried one of the suggestions here: https://stackoverflow.com/questions/38558989/node-js-heap-out-of-memory/59923848#59923848 ?

But i dont want to increase any of ressources, it's working in v11 so what's going on with node v12+

Having same issue on a nrwl/nx nestjs application using:
[email protected]
[email protected]

[email protected] and [email protected] are working fine on [email protected] and nx@latest nestjs based projects
[email protected] works only on nestjs based project
Noticed because a nestjs app was moved to nx

Note that we deleted node_modules and package-lock.json between tests

Can be webpack bundling an issue?

same here on node 12 I can get rid of the issue as from OP.

Seeing same. Getting this error on GAE.

Was this page helpful?
0 / 5 - 0 ratings