Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Functions: Unclear "connection error"

I am getting this error every so many runs with my HTTP Firebase Cloud Function:

Function execution took ****ms, finished with status: 'connection error'

It happens inconsistently but I can't quite narrow down what the problem is. I don't believe the error is in my app as it's not showing an error printout. And my own connection with firebase while running this cloud function isn't cutting out.

Any ideas why Firebase randomly fails cloud function executions with "connection error"?

like image 644
Kyle Hotchkiss Avatar asked Jun 16 '17 21:06

Kyle Hotchkiss


3 Answers

Function execution took ****ms, finished with status: 'connection error' or ECONNRESET usually happens when a function doesn’t know whether a promise resolved or not.

Every promise must be returned, as mentioned in the docs here. There is also a blog post (with helpful video!) about this.

A couple of examples of unreturned promises:

exports.someFunc = functions.database.ref('/some/path').onCreate(event => {
     let db = admin.database();

     // UNRETURNED PROMISE
     db.ref('/some/path').remove();

     return db.ref('/some/other/path').set(event.data.val());
});
exports.makeUppercase = functions.database.ref('/hello/{pushId}').onWrite(event => {
    return event.data.ref.set('world').then(snap => {

      // UNRETURNED PROMISE
      admin.database().ref('lastwrite').set(admin.database.ServerValue.TIMESTAMP);

    });
});
exports.makeUppercase = functions.database.ref('/hello/{pushId}').onWrite(event => {

    // UNRETURNED PROMISE
    event.data.ref.set('world').then(snap => {
        return admin.database().ref('lastwrite').set(admin.database.ServerValue.TIMESTAMP);
    });
});

To help catch this mistake before deploying code, check out this eslint rule.

For an in-depth look at promises, here are some helpful resources:

  • Mozilla docs
  • Ponyfoo promises deep dive
  • Links to the ECMA standard
  • Egghead.io course
like image 194
Jeff Avatar answered Nov 12 '22 22:11

Jeff


Even though this question has an approved answer, you may have followed the steps in that answer and still reached a point where the error was still occurring.

In that case, we were informed by GCP that there's a known issue with Node 8 CFs and this connection error, for which the workaround is to update the node version to 10.

Related github issue: https://github.com/firebase/firebase-functions/issues/429

Specific comment: https://github.com/firebase/firebase-functions/issues/429#issuecomment-577324193

like image 5
Dave Espionage Avatar answered Nov 13 '22 00:11

Dave Espionage


I think it might be too many simultaneous firebase database connections :/ https://groups.google.com/forum/#!topic/firebase-talk/4RjyYIDqMVQ

like image 1
pete Avatar answered Nov 13 '22 00:11

pete