Comments (9)
@tsaarikivi Are you aware any asynchronous tasks need to be returned in order to keep a firebase-function alive? https://firebase.google.com/docs/functions/terminate-functions
I believe the ECONNRESET was being caused by my function terminating before my asynchronous functions were actually finished.
e.g: What not to do
//Example of what NOT to do
exports.lineItem = functions.database.ref('/carts/{userId}').onWrite(event => {
admin.database().ref('somewhereElse').set({success: true});
});
e.g: What should be done (Notice the return)
//Example of returning the asynch/promise
exports.lineItem = functions.database.ref('/carts/{userId}').onWrite(event => {
return admin.database().ref('somewhereElse').set({success: true});
});
I had been doing this in all my functions, but in one specific function I was using another function passing a callback, and had confused myself with my returns.
Best way to test is (if you're doing anything asynchronously):
- add a few console.logs() within the asynchronous call
- Check your firebase-function logs
- Click the three dots at the end of one of the console outputs to 'View all from this execution'
- Verify that all logs are between the start and finish logs for the execution
- If you've got logs after the function's completion log, you're probably not returning your promises correctly 👍
from firebase-functions.
Hey @ahaverty you're absolutely right! I'm glad you were able to figure this out. Having your functions pre-maturely return also explains the log line "Firebase app named "admin" has already been deleted." The SDK deletes apps after the function's return promise resolves in order to prevent concurrency leaks. So when your function doesn't return the promise, but returns undefined, the app gets deleted before the 'set' operation executes. So it cannot successfully execute.
I'm closing this issue now since it's been resolved.
from firebase-functions.
I think I'm going to try return the function and wrap things in Promise.all() like I do with everything else. I'll leave this open as I'm not sure this was causing the two errors, but it's probably not coincidence they were happening on only one of my functions.
from firebase-functions.
Fixing up my promise/task returns seems to have fixed it. I can see others on slack functions channel talking about ECONNRESET issues, perhaps they're stuff is running beyond the function shutdown also? I'll mention my issue in there and see 👌
from firebase-functions.
@ahaverty
I'm sorry, what exactly do you mean by fixing promise/task returns? Could you post a how to not and how to difference. I think this might be the issue for me too!
from firebase-functions.
Weird, I actually do return promises so probably not that. But I'll have to recheck my code.
from firebase-functions.
Interested to hear if it solves it for you too, let me know 👌
from firebase-functions.
Thanks @laurenzlong If firebase functions is capable of logging something that late, It might be nice to suggest that late promises is the cause. Looks like a few people's issues this week were caused by them not returning promises properly, I know it's explained a few of mine. Thanks for looking 😁👌
from firebase-functions.
That's a good suggestion! I'll file that ticket internally. Thanks!
from firebase-functions.
Related Issues (20)
- DocumentOptions do not allow parameterized configuration values HOT 2
- Various Firebase functions started reporting crash: Maximum call stack size exceeded HOT 10
- regression with firebase-functions-test wrapping a v1 scheduled function HOT 2
- Please move `node-fetch` as a `devDependency` HOT 1
- `getDownloadURL` function fails in emulator mode if storage rules are not allowed HOT 3
- Consider exporting `SecretParam` type HOT 3
- CORS error when calling v2 functions using onCall HOT 3
- CallableOptions doesn't accept BooleanParam which is accepted by HttpsOptions HOT 2
- Structured logging error context not being serialized HOT 3
- Don't verify auth token on public endpoints HOT 5
- Firebase Blocking Auth Functions Run Incorrectly on Failed Signup HOT 2
- Module '"firebase-functions/v1"' has no exported member 'onInit'. HOT 5
- Single CORS origin ignored for `onCall` HOT 1
- Auth onCreate trigger doesn't trigger in emulators with magic link sign in flow HOT 2
- Firebase Functions v2 missing labels for documentOnwritten HOT 3
- defineSecret creates a list of values in Secret Manager HOT 5
- Firestore triggers have authType unknown when I make updates to documents from the firebase console HOT 2
- [logger]: express deprecated req.host: Use req.hostname instead HOT 1
- Any Document Trigger Failing for nested triggers HOT 4
- onMessagePublished does not acknowledge messages from Google Play Billing HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from firebase-functions.