Realtime DB updates offline to online connection status with big delay of more than 10 minutes (original) (raw)
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
- Be online
- Open application that uses Realtime DB
- Change client computer clock (decrease time by 15 minutes, for example set 14:30 instead of 14:45)
- 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.