Skip to content

Commit 01f36ea

Browse files
authoredJan 29, 2025··
Fix negative offset of reconnect delay (#8718) (#8719)
RTDB Fix negative offset of reconnect delay. Fixes #8718.
1 parent dafae52 commit 01f36ea

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed
 

‎.changeset/chilled-clocks-remember.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@firebase/database": patch
3+
'firebase': patch
4+
---
5+
6+
Fix a potential for a negative offset when calculating last reconnect times. This could cause lengthy reconnect delays in some scenarios. Fixes #8718.

‎packages/database/src/core/PersistentConnection.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,10 @@ export class PersistentConnection extends ServerActions {
797797
this.lastConnectionEstablishedTime_ = null;
798798
}
799799

800-
const timeSinceLastConnectAttempt =
801-
new Date().getTime() - this.lastConnectionAttemptTime_;
800+
const timeSinceLastConnectAttempt = Math.max(
801+
0,
802+
new Date().getTime() - this.lastConnectionAttemptTime_
803+
);
802804
let reconnectDelay = Math.max(
803805
0,
804806
this.reconnectDelay_ - timeSinceLastConnectAttempt

0 commit comments

Comments
 (0)
Please sign in to comment.