Coder Social home page Coder Social logo

Comments (9)

ahaverty avatar ahaverty commented on June 12, 2024 4

@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):

  1. add a few console.logs() within the asynchronous call
  2. Check your firebase-function logs
  3. Click the three dots at the end of one of the console outputs to 'View all from this execution'

screen shot 2017-03-22 at 11 49 28

  1. Verify that all logs are between the start and finish logs for the execution
  2. If you've got logs after the function's completion log, you're probably not returning your promises correctly 👍

from firebase-functions.

laurenzlong avatar laurenzlong commented on June 12, 2024 1

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.

ahaverty avatar ahaverty commented on June 12, 2024

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.

ahaverty avatar ahaverty commented on June 12, 2024

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.

tsaarikivi avatar tsaarikivi commented on June 12, 2024

@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.

tsaarikivi avatar tsaarikivi commented on June 12, 2024

Weird, I actually do return promises so probably not that. But I'll have to recheck my code.

from firebase-functions.

ahaverty avatar ahaverty commented on June 12, 2024

Interested to hear if it solves it for you too, let me know 👌

from firebase-functions.

ahaverty avatar ahaverty commented on June 12, 2024

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.

laurenzlong avatar laurenzlong commented on June 12, 2024

That's a good suggestion! I'll file that ticket internally. Thanks!

from firebase-functions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.