33

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"?

2
  • 1
    Where is the code? If you want to know why it's failing, going to need a repro. Most likely, you aren't returning a promise, resulting in a race condition of some sort. Commented Jul 26, 2017 at 15:42
  • Check cloud function status: status.firebase.google.com In my case there was an incident today that produced this error. twitter.com/leblancmeneses/status/898400647141142531 Commented Aug 18, 2017 at 4:33

7 Answers 7

33

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:

Sign up to request clarification or add additional context in comments.

5 Comments

Definitely take a look at your promises if you are getting this error. I refactored my function and fixed my promises mistakes and the issue was resolved.
My trigger function was working perfectly until I hit this error. Now I stripped out everything and it still shows this error: Function execution took ****ms, finished with status: 'connection error' My code is as shown below: 'use strict'; const functions = require('firebase-functions'); const admin = require('firebase-admin'); module.exports = functions.https.onRequest((req, res) => { res.end(); return null; }); It has to be a firebase bug. Is there something wrong with my trigger?
@JoshuaDyck interesting. Can you please try to delete your function in the Cloud console (console.cloud.google.com/functions) and redeploy? If that doesn't work, please file a support ticket (firebase.google.com/support/contact/troubleshooting) and include your project name and code. We can follow up from there!
Deleting and re-deploying was indeed a temporary fix but this failed once I deployed a second time as explained in my answer below. This behaviour persisted for a day and now it is no longer doing this after changing nothing. Not sure what was happening but it seems to have randomly stopped.
That is odd, and smells like a bug. If you'd like to investigate further, or if it happens again, can you please file a support ticket at firebase.google.com/support/contact/troubleshooting? Support can take it from there.
5

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

1 Comment

I have resolved it by updating to node 10, thanks! "Node.js 8 has been deprecated" is right :D
1

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

10 Comments

The problem is I cannot even figure out how to catch this error.
So, the weirdest thing happened... I realized it wasn't because of too many database connections but rather the way the promises were structured. I have an array of promises and code which puts promises into the array, then I can either return Promise.all(promises) and process them in the next then(), or I can call Promise.all(promises).then within the same block. Remarkably, the latter (nesting the promises) doesn't cause any issues, but the former (chaining the promises) causes firebase to say finished with status connection error. I thought they are supposed to do the exact same thing!
Now I realized that probably wasn't the real reason because the error is not only very flaky, but also its chance of happening is really flaky which can mislead you. Sometimes, it will occur 90% of the time, while others, it only occurs 10% of the time. I'm not even sure if there's a number of times I should retry before concluding that it's no longer reproducible.
I made my firebase code process database in batches of 50 at a time instead of all at once, and then wait for a batch of promises to finish before calling the next batch. Haven't seen that error again yet, fingers crossed. If it happens again I hope the incidence is at least reduced.
my code also has a Promises.all() in it! Interesting!
|
1

I faced the same issue while deploying uninstallTracking event to firebase for android device,

Turns out that the property I was trying to access was available for only some users , So when it couldn't find the property for those other users it gives this error

So first just check the property you are trying to access is there or not

Comments

0

I've been getting this on an HTTP trigger that immediately calls response.end() with no other code!

I had a very complex function that was working great then it stopped working due to this error. I tried for hours playing with my code until there was nothing left but a response.end() and still the error persisted.

I found that by deleting the trigger (deploying my triggers with the offending trigger commented out), then deploying again with the trigger uncommented seems to have fixed it.

Perhaps there is a bug that works in that gets reset when you delete the trigger in the cloud.

Hope this saves somebody some frustration.

3 Comments

I find that when I update my HTTP triggers the error comes up no matter what I do (regardless of my code). In order to avoid the error I have to delete the trigger and create it again EVERY time. On a fresh trigger creation, the error disappears permanently until I update on redeploy.
I'm experiencing the same with storage trigger. If user will upload image while function is updating, function processing this image will return "connection error". I'ts a problem because it can terminate function at random line, and it's leaving my database in inconsistent state.
@Cyganieszka, that would explain why deleting it would resolve the issue. As an update, my issue randomly resolved the next morning without any changes at my end and has not come back. I'm not sure what caused the connection issue with my HTTP trigger but it sounds like it is likely similar to your storage issue.
0

it could be outdated libraries.

  1. go to terminal

  2. inside functions folder write command

npm outdated

this will show all libraries to require to be updated.

  1. To update libraries write command

npm update

  1. deploy cloud functions with

firebase deploy --only functions

Comments

0

For debugging purposes, I did the following:

response.send(someArray.length) 

...which resulted in the following:

response.send(218) 

...which resulted in a bodyless response, just a "status code" (namely 218) being sent. To fix this, I did:

response.send("count: " + someArray.length) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.