firebase-admin-node
firebase-admin-node copied to clipboard
Segmentation fault / std::bad_alloc on node version >= v12
[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 | ❌ |
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
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.
getting the same error with node v14.3.0. Sometimes Abort Trap : 6
I'm having the same issue with node v12 and firebase-admin v9.11.1, actual latest. I tried the suggestions here: https://stackoverflow.com/questions/38558989/node-js-heap-out-of-memory/59923848#59923848, but couldn't make it work.
I found the cause of the problem. Was this library:
With a fresh install, everything was working as expected. Updating
websocket-driver
resolves the issue.
Having the same issue too with fireadmin v10 and nodes (v12,v14,v16,v17). [donwngrading to node v11.15 & fireadmin v9.4.2 is working workaround for now.]
crash logs:
PID 26541 received SIGSEGV for address: 0x0 0 segfault-handler.node 0x0000000108f8e0ba _ZL16segfault_handleriP9__siginfoPv + 298 1 libsystem_platform.dylib 0x00007ff81b436e2d _sigtramp + 29 2 node 0x00000001047959e0 _ZN2v88internal6Object15AddDataPropertyEPNS0_14LookupIteratorENS0_6HandleIS1_EENS0_18PropertyAttributesENS_5MaybeINS0_11ShouldThrowEEENS0_11StoreOriginE + 976 3 node.napi.node 0x0000000108fa4436 _ZN14Secp256k1Addon4InitEN4Napi3EnvE + 1826 4 node.napi.node 0x0000000108fa352d _Z4InitN4Napi3EnvENS_6ObjectE + 18 5 node.napi.node 0x0000000108fa3601 _Z11__napi_InitP10napi_env__P12napi_value__ + 109 6 node 0x00000001041c6956 _Z30napi_module_register_by_symbolN2v85LocalINS_6ObjectEEENS0_INS_5ValueEEENS0_INS_7ContextEEEPFP12napi_value__P10napi_env__S8_E + 838 7 node 0x00000001041cbad7 _ZNSt3__110__function6__funcIZN4node7binding6DLOpenERKN2v820FunctionCallbackInfoINS4_5ValueEEEE3$_0NS_9allocatorISA_EEFbPNS3_4DLibEEEclEOSE_ + 327 8 node 0x00000001041ca6e0 _ZN4node11Environment12TryLoadAddonEPKciRKNSt3__18functionIFbPNS_7binding4DLibEEEE + 320 9 node 0x00000001041ca4bb _ZN4node7binding6DLOpenERKN2v820FunctionCallbackInfoINS1_5ValueEEE + 587 10 node 0x00000001043e1dd9 _ZN2v88internal25FunctionCallbackArguments4CallENS0_15CallHandlerInfoE + 265 11 node 0x00000001043e18a6 _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEESA_NS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EENS0_16BuiltinArgumentsE + 550 12 node 0x00000001043e101f _ZN2v88internal21Builtin_HandleApiCallEiPmPNS0_7IsolateE + 255 13 node 0x0000000104c51eb9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit + 57
Updating
websocket-driver
using latest version of websocket-driver doesn't solve the issue for me
I'm getting the same error when I try to deploy to firebase hosting
Closing due to inactivity