Why Is My Node Script Waiting 60 Seconds To Terminate After A Cloud Firestore Query?
When I run this script from the command line (node script.js), it seems to work fine. All the activities from Firestore get printed to the console, followed by 'done.'. But then th
Solution 1:
Here you go:
var firebaseApp = firebase.initializeApp(config);
var database = firebase.firestore();
database.collection('activities')
.get()
.then(qs => qs.docs.forEach(doc =>console.log(doc.data())))
.then(() => {
console.log('done.');
firebaseApp.delete();
// database.disableNetwork(); // Another way to do this, though not as clean
});
Managed to dig into the code of the .get() call on the collection and see that there is a 60 second timeout in AsyncQueue that lives after everything is done. Figured there must be a disconnect switch somewhere that shortcircuits the inner timers that that google library runs on and found it in firebaseApp.delete() which does the following according to its docs:
(method) firebase.app.App.delete(): Promise
Renders this app unusable and frees the resources of all associated services.
This works for 5.11.1 as well as 6.0.4, I highly recommend upgrading now while you're early in the project. I was using the npm package firebase-admin instead of firebase like you're using and did NOT need to make this call to free resources.
Post a Comment for "Why Is My Node Script Waiting 60 Seconds To Terminate After A Cloud Firestore Query?"