Skip to content

.info/connected does not change to false when offline #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hiranya911 opened this issue Oct 20, 2017 · 38 comments
Closed

.info/connected does not change to false when offline #249

hiranya911 opened this issue Oct 20, 2017 · 38 comments

Comments

@hiranya911
Copy link
Contributor

From firebase/firebase-admin-node#99

I've verified that this issue occurs with latest RTDB code as well (@firebase/database 0.1.2)

Environment

Debian buster
Node.js v 8.5.0
firebase-admin v ^5.0.0

Steps to reproduce:

  1. Start application and wait for console log "Firebase connected!"
  2. Go offline (switch off wifi or remove lan cable etc.)

When internet connection is disabled, application should print "Firebase disconnected".
It seems, it never does!

Relevant Code:

"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!");
  }
});
@google-oss-bot
Copy link
Contributor

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

@google-oss-bot
Copy link
Contributor

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@schmidt-sebastian
Copy link
Contributor

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).

@mikelehen
Copy link
Contributor

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.

@hiranya911
Copy link
Contributor Author

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?

@schmidt-sebastian
Copy link
Contributor

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.

@kkm
Copy link

kkm commented Apr 1, 2018

+1

@AndryBray
Copy link

AndryBray commented May 21, 2018

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:

  • first time offline
  • second time online again (but this is wrong)

@schmidt-sebastian schmidt-sebastian self-assigned this May 24, 2018
@gsushant
Copy link

gsushant commented Jun 4, 2018

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).

@DennisSmolek
Copy link

For me it's never turning true... It's stuck at false..

@vincentwoo
Copy link

I think this is a reasonable argument for using heartbeat keepalive

@DennisSmolek
Copy link

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

@ristiisa
Copy link

I can confirm that it works with 4.1.3 but not with latest version (5.9.0)

@jedierikb
Copy link

on chrome, using 6.0.0, problem persists.

@LanderBeeuwsaert
Copy link

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.

@zabaat
Copy link

zabaat commented Jun 9, 2019

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

@squigglybob
Copy link

+1 on firebase 6.2.0

@nbransby
Copy link

Also seeing this with 6.2.3, what is the plan for this issue as its been open for nearly 2 years now?

@mintu19
Copy link

mintu19 commented Sep 17, 2019

+1 on firebase 6.6.1 on node

@kkm
Copy link

kkm commented Oct 18, 2019

+1 more than 3 still not solved.

@LanderBeeuwsaert
Copy link

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.

@johnnyoshika
Copy link

johnnyoshika commented Mar 5, 2021

Does this work for anyone? This is what I see:

  • If I navigate away from my app or close my tab, it's a clean disconnect and the following immediately happens:
    • ref('.info/connected').on('value') === false
    • onDisconnect() gets called
  • If I set my network status to offline in dev tools, ref('.info/connected').on('value') gets called twice. First with false then with true. So even though I'm offline, it doesn't detect that.
  • If I turn off my WiFi (i.e. dirty disconnect), ref('.info/connected').on('value') === false correctly gets called immediately, but onDisconnect doesn't. It takes a few minutes before onDisconnect gets called, leaving the server thinking that the user is online when s/he isn't for up to a few minutes.

There's some interesting insight about onDisconnected() here: https://stackoverflow.com/a/49547545/188740

@norcrel
Copy link

norcrel commented Mar 10, 2021

Does this work for anyone? This is what I see:

  • If I navigate away from my app or close my tab, it's a clean disconnect and the following immediately happens:

    • ref('.info/connected').on('value') === false
    • onDisconnect() gets called
  • If I set my network status to offline in dev tools, ref('.info/connected').on('value') gets called twice. First with false then with true. So even though I'm offline, it doesn't detect that.

  • If I turn off my WiFi (i.e. dirty disconnect), ref('.info/connected').on('value') === false correctly gets called immediately, but onDisconnect doesn't. It takes a few minutes before onDisconnect gets called, leaving the server thinking that the user is online when s/he isn't for up to a few minutes.

There's some interesting insight about onDisconnected() here: https://stackoverflow.com/a/49547545/188740

This is also happening to me on Chrome. Setting "offline" in dev tools on chrome also caused a false then true to be logged

@oveddan
Copy link

oveddan commented Apr 2, 2021

@johnnyoshika I have the same issue, where I get 2 .info/connected events, the first with value false the second with true.

@johnnyoshika
Copy link

@oveddan it's a very strange behaviour. I think it's a bug.

@LanderBeeuwsaert
Copy link

@schmidt-sebastian
This seems to be a bug that has been happening for some years in a consistent manner.
Is there an idea about/planning for looking into this?

@b2m9
Copy link

b2m9 commented Jun 10, 2021

I'm running into the same issues that toggling network status in the Chrome/Chromium DevTools (v 91.0.4472.77) fires twice and stays in the "online" state (despite network being toggled off). I'm on version 9.0.0-beta.2.

It makes debugging online/offline behavior unnecessarily complicated.

@kkm
Copy link

kkm commented Jun 11, 2021

almost 4 years and still bug.

@oveddan
Copy link

oveddan commented Jun 11, 2021

I built a lot of my application based on this documented feature, and as a result of this bug it's lead to some pretty critical bugs happening in my application. If it's not working as documented and expected, and there doesn't seem to be a stated acknowledgement of the issue or plan to look at it, then why leave it in the documentation?

@Rubilmax
Copy link

Rubilmax commented Jul 7, 2021

If you are using React: it only works when inside a useEffect hook.

React.useEffect(() => {
  database.ref('.info/connected').on('value', (snapshot) => {
    const isOnline = snapshot.val();
  });
}, []);

I'd also advise to use a lodash/debounce to avoid false triggers

@johnnyoshika
Copy link

@Rubilmax, which part are you referring to when you say it works inside of useEffect? I experienced several problems with .info/connected that I outlined here: #249 (comment), but I don't think useEffect will change anything. Are you seeing something different?

@Rubilmax
Copy link

Rubilmax commented Jul 8, 2021

@Rubilmax, which part are you referring to when you say it works inside of useEffect? I experienced several problems with .info/connected that I outlined here: #249 (comment), but I don't think useEffect will change anything. Are you seeing something different?

I am referring to how .info/connecteed is expected to work. Respectively, I tested (locally, using the firebase emulators and I'm using it production now) your 3 use cases with the listener added inside a useEffect and using a debounce of 2000ms and the results were the following:

  • clean disconnect: false, when opening a new tab: true
  • devtools offline: false, then online: true
  • dirty disconnect: false then when re-enabling wifi: true

I did not test any feature related to onDisconnect

I originally posted my comment because at first I was going to register the listener at the root of my app: I had not results and that's the reason I came upon this issue. However, after having moved the listener registering part inside a useEffect in the root component of my app, it's working just as expected.

@johnnyoshika
Copy link

@Rubilmax Thanks. Use case 1 and 3 that you're seeing is the same behavior that I saw for .info/connected. You're seeing a different behavior for use case 2 with dev tools and that's interesting. My .info/connected would get called twice when I went offline in dev tools: once with online==false and once for online==true even if I left it in offline mode.

I still believe there's a problem with onDisconnect.

Note:

  • I didn't re-test my examples, so I'm basing my comments off of my tests I did on March 4th. Things could have changed since then.
  • I did all of my tests inside of useEffect as well

@Ajiharan
Copy link

Ajiharan commented Aug 12, 2021

I have the same situation here. info/connected events called with the first with value false the second with true, then I set my network offline through chrome dev tools .info/connected called twice with value false and the second with true. when I
disconnect my wifi .info/connected called with value false as expected but onDisconnect doesn't call after my wifi
disconnected

firebase version: 8.9.1

@vasujogani
Copy link

vasujogani commented Oct 22, 2021

Any solution to this issue? The issue is getting connected=false, and connected=true right after. It also seems like none of the firebase calls (.set(), .update()) go through once I get this issue.

@maneesht
Copy link
Contributor

@vasujogani are you still having issues on the latest version of the JS SDK?

@google-oss-bot
Copy link
Contributor

Hey @hiranya911. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Contributor

Since there haven't been any recent updates here, I am going to close this issue.

@hiranya911 if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@firebase firebase locked and limited conversation to collaborators Oct 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests