firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

FR: Add possibility to configure RECONNECT_MAX_DELAY_DEFAULT

Open VitaliyTeryokhin opened this issue 2 months ago • 0 comments

Operating System

not relevant

Environment (if applicable)

not relevant

Firebase SDK Version

not relevant

Firebase SDK Product(s)

Database

Project Tooling

not relevant

Detailed Problem Description

What you were trying to achieve

Possibility to configure RECONNECT_MAX_DELAY_DEFAULT in PersistentConnection.ts:

What actually happened

When the WebSocket connection drops and the browser tab is active (visible), the Firebase SDK attempts to reconnect almost immediately. However, when the browser tab is in the background (not visible), the SDK introduces a significant reconnection delay.

From a product perspective, this is problematic because our customers still need to receive communication messages and notifications even when the tab is in the background.

Looking into the Firebase JS SDK source code, we found the following logic in PersistentConnection.ts:

Line 46:

const RECONNECT_MAX_DELAY_DEFAULT = 60 * 5 * 1000; // 5 minutes in milliseconds (Case: 1858)

Line 106:

private maxReconnectDelay_ = RECONNECT_MAX_DELAY_DEFAULT;

Lines 787–788:

this.log_("Window isn't visible. Delaying reconnect.");
this.reconnectDelay_ = this.maxReconnectDelay_;

This suggests that when the window is not visible, the SDK intentionally applies the maximum reconnection delay (up to 5 minutes)

Logs received using enableLogging function

2025-09-17T16:44:14.683Z  c:0:2:0 Websocket connection was disconnected.
2025-09-17T16:47:49.003Z  p:0: Making a connection attempt
2025-09-17T16:47:51.615Z  p response {"s":"ok","d":""}
2025-09-17T16:48:23.373Z  Window became visible. Reducing delay.

Connection attempt was 3 minutes after disconnect, because tab was not visible.

Steps and code to reproduce issue

  1. Establish WebSocket connection using firebase in browser tab, enable logging using enableLogging function. Client implementation is not important.
  2. Put this tab to the background (open another tab) for several hours. It can take quite a long time to receive websocket disconnection event.
  3. Check logs.

VitaliyTeryokhin avatar Oct 14 '25 12:10 VitaliyTeryokhin