Firebase; RangeError: Maximum call stack size exceeded

518 Views Asked by At

Hi I have tried all solutions provided for this error including using .once('value') instead of .on('value'). I have however not been able to solve it. My code[shown below] runs for some time around 2-3 days then crashes with the error below.

RangeError: Maximum call stack size exceeded
at JSON.stringify (<anonymous>)
at A (/home/qymspace/Code/threeneelchannel/node_modules/firebase-admin/lib/database/database.js:57:351)
at Pf.h.send (/home/qymspace/Code/threeneelchannel/node_modules/firebase-admin/lib/database/database.js:161:146)
at sg (/home/qymspace/Code/threeneelchannel/node_modules/firebase-admin/lib/database/database.js:177:164)
at hg.ua (/home/qymspace/Code/threeneelchannel/node_modules/firebase-admin/lib/database/database.js:174:158)
at Object.ua (/home/qymspace/Code/threeneelchannel/node_modules/firebase-admin/lib/database/database.js:233:302)
at kh.h.ua (/home/qymspace/Code/threeneelchannel/node_modules/firebase-admin/lib/database/database.js:222:143)
at uh (/home/qymspace/Code/threeneelchannel/node_modules/firebase-admin/lib/database/database.js:227:82)
at th (/home/qymspace/Code/threeneelchannel/node_modules/firebase-admin/lib/database/database.js:226:435)
at kh.h.put (/home/qymspace/Code/threeneelchannel/node_modules/firebase-admin/lib/database/database.js:226:258)

My code is :

    const firebase = require('firebase-admin');
    const Queue = require('firebase-queue')
    const serviceAccount = require("./threeneel-5ad39-firebase-adminsdk-2wjww-145ef9bc19.json");
    const config = {
    credential: firebase.credential.cert(serviceAccount),
    databaseURL: "https://threeneel-5ad39.firebaseio.com",
  };
firebase.initializeApp(config);
const database = firebase.database();
var count =0;
var newPosts = [];
var posts=[]
var key="key"
var number= 0
         posts=data.posts;
     key=data.key;
     number= posts.length;

    console.log('database.isNew: key: ',key);  
    const queueRef = database.ref('channel/queue')
    posts.forEach((item)=>{
        queueRef.child('tasks').push({item});
    })
    var queue = new Queue(queueRef,function(data,progress,resolve,reject){
        //do processing on queue
        database.ref('/channel/posts').child(link2id(data.item.link)).once('value',(snapshot)=>{
            if(snapshot.val()===null){
                newPosts.push(data.item)
            }
            count++;
            console.log('Number: ',number," Count: ",count,'Link: ',data.item.link);
            if(count < number){
                resolve() 
            }
            else{
                count=0;
                resolve();
                console.log('database.isNew(2): Key: ',key);
                onReceive({key:JSON.parse(JSON.stringify(key)),posts:JSON.parse(JSON.stringify(newPosts))})
                newPosts=[];
            }   
        })
    });

When I check in the firebase data usage page the usage is around 5% which is quite is small I think. Firebase data usage: Downloads

Firebase data usage: Load

0

There are 0 best solutions below