Closed hiranya911 closed 1 year ago
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
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.
Does this work for anyone? This is what I see:
ref('.info/connected').on('value')
=== falseonDisconnect()
gets calledref('.info/connected').on('value')
gets called twice. First with false
then with true
. So even though I'm offline, it doesn't detect that.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
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')
=== falseonDisconnect()
gets called- If I set my network status to offline in dev tools,
ref('.info/connected').on('value')
gets called twice. First withfalse
then withtrue
. 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, butonDisconnect
doesn't. It takes a few minutes beforeonDisconnect
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
@johnnyoshika I have the same issue, where I get 2 .info/connected
events, the first with value false the second with true.
@oveddan it's a very strange behaviour. I think it's a bug.
@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?
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.
almost 4 years and still bug.
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?
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
@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: https://github.com/firebase/firebase-js-sdk/issues/249#issuecomment-791199152, but I don't think useEffect
will change anything. Are you seeing something different?
@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 thinkuseEffect
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:
false
, when opening a new tab: true
false
, then online: true
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.
@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:
useEffect
as wellI 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
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.
@vasujogani are you still having issues on the latest version of the JS SDK?
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!
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.
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
)Environment
Debian buster Node.js v 8.5.0 firebase-admin v ^5.0.0
Steps to reproduce:
When internet connection is disabled, application should print "Firebase disconnected". It seems, it never does!
Relevant Code: