Skip to content
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

Realtime DB updates offline to online connection status with big delay of more than 10 minutes #8718

Closed
alexander-at-t opened this issue Jan 23, 2025 · 1 comment

Comments

@alexander-at-t
Copy link
Contributor

Operating System

macOS Sonoma 14.6.1

Environment (if applicable)

Chrome 130

Firebase SDK Version

11.2.0

Firebase SDK Product(s)

Database

Project Tooling

Javascript + React + Webpack

Detailed Problem Description

Realtime should quickly reconnect after connection lost.

But there is a bug in Firebase JS SDK that leads to delays before reconnect attempt that exceeds max constant values.

Steps and code to reproduce issue

Steps

  1. Be online
  2. Open application that uses Realtime DB
  3. Change client computer clock (decrease time by 15 minutes, for example set 14:30 instead of 14:45)
  4. Turn off wifi

You will see that Realtime DB may try to reconnect in 3 minutes even for Admin accounts (for Admin accounts constant maximum is 30 seconds).

The bug is in this code:

const timeSinceLastConnectAttempt =
new Date().getTime() - this.lastConnectionAttemptTime_;
let reconnectDelay = Math.max(
0,
this.reconnectDelay_ - timeSinceLastConnectAttempt
);
reconnectDelay = Math.random() * reconnectDelay;
this.log_('Trying to reconnect in ' + reconnectDelay + 'ms');
this.scheduleConnect_(reconnectDelay);
// Adjust reconnect delay for next time.
this.reconnectDelay_ = Math.min(
this.maxReconnectDelay_,
this.reconnectDelay_ * RECONNECT_DELAY_MULTIPLIER
);

So timeSinceLastConnectAttempt may become negative, and so lead to significant exceeding of max delays defined in constants.

@alexander-at-t alexander-at-t added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Jan 23, 2025
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

alexander-at-t added a commit to alexander-at-t/firebase-js-sdk that referenced this issue Jan 23, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@jbalidiong jbalidiong added api: database needs-attention and removed needs-triage new A new issue that hasn't be categoirzed as question, bug or feature request labels Jan 23, 2025
@DellaBitta DellaBitta self-assigned this Jan 24, 2025
This was referenced Feb 5, 2025
@firebase firebase locked and limited conversation to collaborators Feb 28, 2025
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

4 participants