firebase / firebase/firebase-js-sdk

FR: Add possibility to configure RECONNECT_MAX_DELAY_DEFAULT

Open
#9,318 0 comments 0 reactions 0 assignees View on GitHub
api: database type: feature request
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### 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:](https://github.com/firebase/firebase-js-sdk/blob/main/packages/database/src/core/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:](https://github.com/firebase/firebase-js-sdk/blob/main/packages/database/src/core/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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.