From https://github.com/firebase/firebase-admin-node/issues/99
I've verified that this issue occurs with latest RTDB code as well (@firebase/database 0.1.2)
Debian buster
Node.js v 8.5.0
firebase-admin v ^5.0.0
When internet connection is disabled, application should print "Firebase disconnected".
It seems, it never does!
"use strict";
var path = require('path');
var admin = require("firebase-admin");
var serviceAccount = require(path.join(__dirname, "some-firebase-adminsdk-lu0x5-82c66d50f5.json"));
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://some.firebaseio.com/"
});
const database = admin.database();
var connectedRef = database.ref(".info/connected");
connectedRef.on("value", function(snap) {
if (snap.val() === true) {
console.log("Firebase connected!");
} else {
console.log("Firebase disconnected!");
}
});
Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.
Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.
Hiranya, do you know if this a Node only issue? Our networking layer is different in Node and I wonder whether this is something we never supported (it also doesn't make as much sense in Node as it does on the mobile platforms).
FWIW, I would expect it to work (the websocket connection should die and trigger .info/connected to change), but it may take a really long time (e.g. 15 minutes) depending on OS TCP timeout settings, etc.
I have only tested this in Node (with the Admin SDK). I think @mikelehen may be right. I remember seeing this event fire long time (> 15 mins) after a disconnect. Since the delay was long, I brushed it off as a fluke. I also agree that it is not a very popular use case for server-side environments. So may be we can just ensure it works in the web SDK, and document the behavior for Node?
It really depends on the underlying network stack. We have seen that this event doesn't fire for a full hour on some Android devices as the TCP retry window prevents the network stack from bubbling up these connection drops.
+1
I have the same after upgrading to 4.1.5 (https://firebase.google.com/support/release-notes/js) - previous versions where OK.
It's like the event is fired twice:
As @AndryBray pointed out, I am having the same issue (event firing twice - offline followed by online). The example at: https://firebase.google.com/docs/database/web/offline-capabilities#section-presence works fine with 4.1.3 but doesn't work with 4.1.4 (and 5.0.4).
For me it's never turning true... It's stuck at false..
I think this is a reasonable argument for using heartbeat keepalive
Just for posterity, My issue was somewhere in the system it disconnected using goOffline to stop permissions issues from firing errors. Even after reconnecting I realized messing with the DB's connection state can cause problems with .info
I can confirm that it works with 4.1.3 but not with latest version (5.9.0)
on chrome, using 6.0.0, problem persists.
I have the same as @AndryBray : when simulating a disconnect in chrome by using devtools, I get an offline directly followed by online.
If I run:
async isConnected(): Promise
return (await database()
.ref('.info/connected')
.once('value')).val();
}
then it returns true, while I have in the network tab of chrome devtools that I'm offline.
version: "firebase": "6.0.2",
Persistency is off.
Having same issue as well
firebase 5.10.0
when simulating a disconnect in chrome by using devtools, I get an offline directly followed by online.
When i disconnect internet connection it doesn't even fire an offline.
Also occurs with firebase 6.1.1
+1 on firebase 6.2.0
Also seeing this with 6.2.3, what is the plan for this issue as its been open for nearly 2 years now?
+1 on firebase 6.6.1 on node
+1 more than 3 still not solved.
Just encountered this again, with latest libraries.
Maybe can be interesting:
When I disconnect my wifi, it works fine. When I do a disconnect in chrome devtools network tab, it gives the issue.
Most helpful comment
I have the same as @AndryBray : when simulating a disconnect in chrome by using devtools, I get an offline directly followed by online.
If I run:
async isConnected(): Promise {
return (await database()
.ref('.info/connected')
.once('value')).val();
}
then it returns true, while I have in the network tab of chrome devtools that I'm offline.
version: "firebase": "6.0.2",
Persistency is off.