Firebase timeouts, slow responses

Did anyone using Firebase with Ionic run into this issue?

I’ve started implementing Firebase as the backend for my Ionic app (for auth and data) but I’m having one serious problem.

As long as I tested in a web browser (“ionic serve”) everything looked okay.

However once I started testing on a device (Android, Samsung Galaxy S3) with “ionic run”, the trouble began.

The problem I had (on the Android device) is that the response time on my auth/read/write operations was unpredictable. Most of the time it was like 2 to 4 seconds (for auth, retrieve or store), but occasionally (one out of ten) it was much longer (up to 30 seconds or a minute or a complete “hang”).

This happened with all operations: ref.authWithPassword(), ref.on() or ref.once(), ref.set() and so on. It seemed to be a random thing, the same operation that takes 2 seconds can take 30 seconds when I tried it a minute later.

After switching on detailed logging (Firebase.enableLogging), I saw this, for a “ref.authWithPassword”:

I/chromium( 8110): [INFO:CONSOLE] “2015-09-03 01:02:44 - Login start …”

I/chromium( 8110): [INFO:CONSOLE] "2015-09-03 01:03:00 - 2015-09-02T23:03:00.505Z: c:0:0: Closing unhealthy connection after timeout. "

So, the login operation starts at 1:02:44 (call to “ref.authWithPassword”), and then at 01:03:00 (16 seconds later), I see “Closing unhealthy connection after timeout”.

I suspect that in the other cases where I had a “slow” operation the issue is the same: it’s timing out on an “unhealthy connection”.

This happened late in the evening and when I re-tested the following morning the issue was gone. Scary because if this happens too frequently it’s sure to “kill” your app.

Did anyone else experience something like this? As I said it seemed to happen only on a device (maybe only on that particular device?), when testing in the browser I’ve never seen it.

1 Like

Come on guys, nobody out there with some Firebase experience who ran into this issue? I can’t imagine that I’m the only one running into this (but okay, maybe I am).

Firebase is apparently hugely popular with Ionic devs, this is going so far as it even being recommended (semi-officially, kind of) by the Ionic team.

Now mind you, I can understand why because I like it a lot as well, if it works, that is.

Fact is, I didn’t encounter this issue for days, but yesterday evening it was back in full force. Not just slow responses but completely “hung” on requests.

I still have the idea that this is somehow related to the device on which I’m testing, because I didn’t encounter it when testing in the browser on a desktop with “ionic serve”. Must have something to do with the device freaking out on managing its network connections.

Now my only fear is if this would happen after publishing my app on the appstore.

Maybe it won’t if this is just an artifact of testing on a device with “ionic run” and the app being reinstalled/killed/restarted numerous times on an Android device in ‘debug’ mode. But if it would then it would be killing for the app’s user experience and potentially for the app as such.

There’s a few options I have:

  • very thorough automated stress testing on a number of devices e.g. with Amazon Device Farm (afraid that can get costly quickly after the first free 250 minutes) or in-house e.g. with Appium
  • build in some kind of timeout/retry mechanism, see e.g. https://github.com/bahmutov/angular-q-timeout
  • rip out and replace Firebase which is obviously the least attractive option by far

Ideas or advice are welcome.

The problem with firebase is… that it is okay for private projects stuff i think… but as a german company we can not work with such services. We are creating special backends and nodejs apis… so firebase would be an additional effort… and it stores the data on us-servers :smile:

But your problem can occur on any other cloudbased system if they have heavy traffic or network problems. The advantage is you have a backend as a service and no need to manage backend and server on your own.

Maybe firebase was deploying some changes to their services and serves and logins were not allowed?

That’s interesting, why wouldn’t you be able to use Firebase when you are a German company, is there any government regulation or EU regulation prohibiting you from using it?

I suppose if you are in the banking or payments industry (heavily regulated), or government/military, or extremely security/privacy sensitive stuff, then you couldn’t use a cloud service, but for a normal consumer/business type of app would there be a problem?

Eventually we might build our own backend but as a very small startup (2 persons with only 1 tech person) building a “concept of proof”/prototype/MVP (minimum viable product) we don’t want to spend time and effort on building a backend now.

When the product takes off and when we have some time then chances are we will probably build/host our own backend, it isn’t rocket science to do it. But if I’d do that now it would mean I’d be pushing the schedule back with 2 or 3 weeks at least.

we could use us-services but in germany and some other european countries we have very strict data protection rights… so most people think our hosters are “safer” for legal projects :smile:… in any other cases you can use the coconut isles :slight_smile:

Okay interesting, we’re based in the Netherlands so it would probably be wise to do some quick research into the legal rules.

On the other hand as long as we’re in the alpha/beta/‘proof of concept’ phase then I think Firebase is fine anyway, speed of development and being able to quickly show a working product is more important now.

When we see that the app is being received well and we have all the functionality flashed out then I suppose it won’t be a big deal to rip out Firebase and replace it with a custom backend (nodejs probably).

netherlands is good if you provide restricted content for underaged :wink: there is no special right and i think no need to ask how old the user is… sexual and violent content doesn’t matter…

Okay that’s good to know :wink: even though we weren’t planning to do that kind of stuff.

I’ll just add another “check this” item to my ever-growing to-do list. Need to prioritize stuff and postpone the lesser worries until later, otherwise this thing will never get finished.

1 Like

Maybe you can try this : Ionic / firebase stuck loading forever

The problem is not from firebase but from Ionic/Cordova, Ionic inject cordova automatically but after the firebase connection start (for my project) , this make that the browser stop and restart (for now I don’t know why).

If you add cordova.js at the top of your project, it will be fine, but for now the ionic will not work, you will have the same problem , since ionic doent upload the cordova.js file, didn’t find a way to get rid of that…

1 Like

Wow thanks a lot! Didn’t see that other thread yet. So the idea is to take out the ionic.io libraries and only keeping in cordova.js because something there is interfering with Firebase connection management.

I’m not 100% sure if my situation is exactly the same (I rarely have the issue to be honest, for me it’s not reproducible) but I’ll just go ahead and make this change: take out the ionic.io libs for now (I wasn’t planning to use them for “production” anyway yet), and then I’ll keep testing to see if I run into the issue again.

Again this proves what a great asset the fantastic Ionic community and forum is.

It’s a main reason why I have great trust in using Ionic for my app: for almost any issue you run into you can find answers on the Ionic forum or otherwise on Stackoverflow (obviously it also helps a lot that the product is based on Angular and on Cordova).

Apart from that, alternatives such as Nativescript, while potentially interesting, are not yet mature enough and don’t have as much of a community around them, so for any issues you run into you’re largely on your own.

Besides, at this stage it’s much harder to produce a nice looking UI with Nativescript (even though the UI is “native”) than with Ionic. And you need to be prepared to invest a lot more time in “cross-platform”.

Finally I think the performance gap of “hybrid”, if any, is closing fast. Mostly it’s an issue on older Android devices, devices less than 2 years old and iOS devices whatsoever don’t have any issue with performance.

So did you find a solution for that? because my users tell me that they stay a long time to load data and someone unistall it :frowning:

thank’s

Well, yes I did.

I followed the advice given here:

Ionic / firebase stuck loading forever

and especially:

Ionic / firebase stuck loading forever

and also:

http://stackoverflow.com/questions/31219005/firebase-requests-stalling-at-negotiation-phase-how-to-debug

That is, I uninstalled the Ionic.io libraries (Ionic Core and Ionic Analytics), so, in my index.html:

  <!-- Took out the ionic.io libs because of Firebase issues as described here: -->
  <!--    http://forum.ionicframework.com/t/firebase-timeouts-slow-responses/31657/10 -->
  <!--    http://forum.ionicframework.com/t/ionic-firebase-stuck-loading-forever/31146/12- ->
  <!--<script src="lib/ionic-service-core/ionic-core.js"></script>-->
  <!--<script src="lib/ionic-service-analytics/ionic-analytics.js"></script>-->

Like this.

Since then, I NEVER again experienced the issue.

Note: in the above threads, people are talking about the fact that they see “cordova already loaded” in the console logs. This is due to the Ionic.io libraries which apparently also load cordova.js.

They then commented out cordova.js.

I took the opposite approach and took out the Ionic.io libraries but left cordova.js in.

I THINK that both approaches will work, and under the hood are due to the same underlying root cause.

I just leave this to thank you leob. I’ve just had my app rejected for this very specific problem and at least I know from where to start for having it solved. In two more weeks probably, considering Apple’s timings.

Anyway, I live in the Netherlands as well, maybe we’ll catch up at some events. Cheers,


Davide

Hey that’s cool. Well I heard that Apple is very critical and that it’s harder to get your app approved in the Apple Store than in Google’s Play Store.

That’s why I told my client for whom I’m developing 2 apps that we’re going to submit version 1.0 only to the Google store initially because doing the Apple store will cost me too much time (not to mention 99 USD for the Apple dev membership).

Another thing that may be interesting: did you hear that there’s now an Ionic Web Client which intends to replace the “ionic.io” libraries? I still need to evaluate that but when I do I’ll check closely if it doesn’t bring back the same issues with Firebase which the “ionic.io” libraries were causing.

(the functionality that I’m interested in obtaining through the Web Client is mainly Ionic Deploy which allows you to update your app by downloading the HTML/CSS/JS without having to go though app store approval again)

Anyway, for the rest I have to say I’m extremely impressed by and satisfied by Firebase: its ease of use (simple and elegant API), stability/reliability and speed/low latency.

you are not the only one, i too expereincing the slow or never response isue from firebase promise, sometime it takes more than 10 minutes to return promise from a push(), all other functions working,