Skip to content

Commit

Permalink
Fix negative offset of reconnect delay (#8718) (#8719)
Browse files Browse the repository at this point in the history
RTDB Fix negative offset of reconnect delay. Fixes #8718.
  • Loading branch information
alexander-at-t authored Jan 29, 2025
1 parent dafae52 commit 01f36ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/chilled-clocks-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@firebase/database": patch
'firebase': patch
---

Fix a potential for a negative offset when calculating last reconnect times. This could cause lengthy reconnect delays in some scenarios. Fixes #8718.
6 changes: 4 additions & 2 deletions packages/database/src/core/PersistentConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,10 @@ export class PersistentConnection extends ServerActions {
this.lastConnectionEstablishedTime_ = null;
}

const timeSinceLastConnectAttempt =
new Date().getTime() - this.lastConnectionAttemptTime_;
const timeSinceLastConnectAttempt = Math.max(
0,
new Date().getTime() - this.lastConnectionAttemptTime_
);
let reconnectDelay = Math.max(
0,
this.reconnectDelay_ - timeSinceLastConnectAttempt
Expand Down

0 comments on commit 01f36ea

Please sign in to comment.