Firebase connection is lost and never come back

My pleasure. Okay let’s keep in touch. Happy new year to you :wink:

Honestly, it’s been almost a year that my app ( is in production mode, with tens of thousands of users using it daily, and I haven’t encountered a single problem with Firebase since I manually handled the connection / disconnection on pause/resume of the app.

Hopefully you can get it to work for you as well @aicokleinovink ! :slight_smile:

Happy new year to all of you !

Thanks for your reply @pierro, I tried it first with the addEventListener as you described, but I wasn’t sure it really fired anything. Now I’ve implemented it with platform.pause and platform.resume. I can confirm that it does fire when the app goes to the background. Put the Firebase.goOffline() and Firebase.goOnline() code there. I’ll have to wait some (random) hours to see if it keeps the data in my app, really hope it does! Keep you posted! Your app looks very nice btw!!

This morning I lost all firebase data again in my view after it has been 12+ hours in the background. Please @pierro can you provide some snippets on how you fixed this? Maybe I’m doing something wrong, or something that I’m missing??

Are you also ‘subscribing’ to your firebase ref? Or getting snapshots with ‘child_added’ and stuff?

Would really appreciate some help!

Can you explain what you mean by “losing all your firebase data”?
Just an overview of what your app is doing and what kind of data you are fetching might help.

To answer your question, I am getting snapshots with:
myFirebaseRef.on('value', function(data) {


This way, once I resume my app it goes back online and it checks if there is anything new on this firebase node by itself.

And my resume event is in my app.js (Ionic V1)

document.addEventListener("resume", function () {

First of all, I use Ionic v2 with AngularFire2. I also experiencing this problem when viewing my app inside IonicView.

With ‘losing my data’, I mean the following:

  • I have a timeline which displays some messages related to a ‘events’ object in my Firebase database. Each message is displayed in a Ionic ‘card’ element (like Facebook).
  • After a while, when I resume my app (and data is lost) the cards are still there, they are just empty. So the ‘binding’ or relation to the events database object is lost. So the HTML elements are still there, only all data from the database is simply not there anymore.

Currently I’m subscribing to the database object as following:

public timelineEvents: Event[];

constructor(af: AngularFire) {
    const events$: FirebaseListObservable<any> = af.database.list(`events`);
        (data: Event[]) => this.timelineEvents = data,
        (error: firebase.FirebaseError) => console.error(error)

Maybe subscribing instead of the on value function is a problem?? I will refactor this to test if this is causing the behavior.

Right now, I’ve implemented the going online and offline as following in the main app.component.ts:
(I’ve tested the platform.pause and platform.resume, those will fire)

constructor(private platform: Platform) {
        platform.pause.subscribe(() => Firebase.goOffline());
        platform.resume.subscribe(() => Firebase.goOnline());

Maybe you have some other ideas??

Hi Guys,

I’ve been experiencing a similar issue all of a sudden too.
I’ve started testing the app on Android 7 after is has been working perfectly on Android 6 for some time now.
After coming from the background, firebase cannot re-connect. This seems to happen in random intervals and cannot be re created manually.

    "firebase": "4.12.1",
    "ionic-angular": "3.9.2",
    "angularfire2": "5.0.0-rc.5-next",

Just to make it clear, there is an internet connection. Rest API calls other than Firebase from the app get called successfully.

The console shows the following errors:

 {code: "auth/network-request-failed", message: "A network error (such as timeout, interrupted connection or unreachable host) has occurred."}

vendor.js:1 ERROR Error: Uncaught (in promise): FirebaseError: [code=aborted]: Failed to get document because the client is offline.
FirebaseError: Failed to get document because the client is offline.

failed: WebSocket is closed before the connection is established.

Did you get to resolve this issue eventually?

Thanks in advance