RocketChat / Rocket.Chat

The communications platform that puts data protection first.
https://rocket.chat/
Other
40.7k stars 10.67k forks source link

User Online Status stays "Offline" after internet outage #21899

Open wreiske opened 3 years ago

wreiske commented 3 years ago

Description:

The user's status stays "offline" and can't be changed to "online" after the internet connection is interrupted. This can be due to a VPN dropping, the internet going out, bad WIFI, etc....

When the internet comes back and the user reloads the page, their status shows as "offline" and can't be changed to "online" without first setting it to away and then back to online.

Steps to reproduce:

  1. Visit open.rocket.chat

  2. Open DevTools image

  3. Go to the Network tab and set the network state to "offline." This effectively emulates what happens when the internet goes out. image

  4. Wait a few moments, maybe a minute just to be sure, and then click around into another channel. You'll see an "undefined" error here and the channel will fail to load. image

  5. Realize "oh, my Wi-Fi disconnected" or "Oh! My VPN Dropped!" and reconnect. In this example, we'll just set the network state back to "Online" image

  6. Now that you're reconnected, hit View -> Reload. image

  7. Your status is now stuck "Offline" QuNH1WNHCv

Expected behavior:

After reloading, the status should be Online!

Actual behavior:

See step 7 above.

Server Setup Information:

Client Setup Information

tobias-mierzwa commented 3 years ago

Same problem here.

Server Setup Information:

Client Setup Information

ugzv commented 3 years ago

Same problem here. My status appears offline, when I am present. Refreshing/reloading the Windows client doesn't help.

xadhoom commented 3 years ago

For some reason internally it thinks that you're online, so it does not do the transition online-online. If you select busy or away it changes correctly and after is possible to select back to online.

Happens also on https://open.rocket.chat .

zaphod534 commented 3 years ago

It looks like a synchronization problem, as the user status (and statusConnection) in the db is correct. After some investigation, I noticed that the client fetches user information on startup, but by that time the user has not yet been updated on the server.

By adding a delay here the problem seems to no longer occur.

zaphod534 commented 3 years ago

Getting user's data in Accounts.onLogin callback seems to solve the issue. @g-thome do you think this is an acceptable solution?

diff --git a/client/startup/startup.ts b/client/startup/startup.ts
index d226716c0..d05e635bc 100644
--- a/client/startup/startup.ts
+++ b/client/startup/startup.ts
@@ -37,7 +37,7 @@ Meteor.startup(() => {
        window.lastMessageWindowHistory = {};

        let status: UserStatus | undefined = undefined;
-       Tracker.autorun(async () => {
+       Accounts.onLogin(async () => {
                const uid = Meteor.userId();
                if (!uid) {
                        return;