why after creating a number of documents in sub-collection I get Cloud Function memory leak warning?

Viewed 359

So I use :

  1. Node 14
  2. firebase-admin 9.5.0
  3. firebase-functions 3.13.2
  4. firebase-tools 9.8.0

so I still use Firestore and Cloud Function emulators, not deployed in real production server yet.

all documents in Firestore emulators will be erased whenever I turn off the server, right.

so I create a script to populate firestore emulators. I use cloud function http trigger, so after I hit that endpoint, then the Firestore emulators will be populated with my documents needed. I create http trigger like this

export const populateFirestoreData = functions
.https.onRequest(async (req, res) => {

    // I create 5 dummy user documents
    creatingDummyUsers()

    // then create 8 dummy event documents in attendedEvents sub-collection
    creatingDummyAttendedEvents()

})

function creatingDummyUsers() {

    const dummyUsers = []; // 5 data here

    const promises = dummyUsers.map( (dummyUser) => db.doc(`users/${dummyUser.uid}`).set(dummyUser);
    await Promise.all(promises)

}

function creatingDummyAttendedEvents() {

    const dummyEvents = []; // 8 data here

    const promises = dummyEvents.map( (dummyEvent) => db.doc(`users/${dummyEvent.userID}/attendedEvents/${dummyEvent.id}`).set(dummyEvent);
    await Promise.all(promises)

}

inside that function, I create some user documents, and a user has sub-collection called attendedEvents. so the structure of my collections and documents will be like this

users/{userID}/attendedEvents/{eventID}

enter image description here

I also have another function (firestore trigger), so whenever a document is created inside attendedEvents sub-collection then I need to do something

exports.onCreate = functions
.region(CLOUD_FUNCTION_DEFAULT_REGION)
.firestore.document("users/{userID}/attendedEvents/{eventID}")
.onCreate(async (snapshot, context) => {

    // I do nothing in here, but still I have this problem

    return null;

});

here is the problem ....

if I just make 7 event documents to attendedEvents, then all be fine. but whenever I make 8 event documents to attendedEvents then I will have this warning

enter image description here

node:6340) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 log listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit (Use node --trace-warnings ... to show where the warning was created)

something wrong whenever I create 8 event document in attendedEvents sub-collection, because it will trigger function users_attendedEvents-onCreate

unfortunately, I don't know how to stack trace the warning by using that node --trace-warnings . I am a newbie in nodeJS

I actually create more dummy documents than just user documents and attendedEvents documents, but I find this warning whenever I create 8 attendedEvents documents (7 docs is ok).

I will have the same problem if I use batched writes

I hit some limit? is it only in emulator? is it a bug?

0 Answers
Related