Skip to content

Commit

Permalink
Fix exponential backoff delay overflow (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
leolabs authored Mar 21, 2022
1 parent 24403ed commit 8b5073f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## Unreleased
## 3.0.5

- fix: Limit retryDelay to avoid integer overflows in setTimeout (#441)

## 3.0.5

Expand Down
7 changes: 7 additions & 0 deletions src/main/transports/electron-offline-net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ElectronNetTransport, HTTPError, SentryElectronRequest } from './electr
import { PersistedRequestQueue } from './queue';

const START_DELAY = 5_000;
const MAX_DELAY = 2_000_000_000;

/** Returns true is there's a chance we're online */
function maybeOnline(): boolean {
Expand Down Expand Up @@ -73,6 +74,12 @@ export class ElectronOfflineNetTransport extends ElectronNetTransport {

this._retryDelay *= 3;

// If the delay is bigger than 2^31 (max signed 32-bit int), setTimeout throws
// an error and falls back to 1 which can cause a huge number of requests.
if (this._retryDelay > MAX_DELAY) {
this._retryDelay = MAX_DELAY;
}

return { status: 'unknown' };
}

Expand Down

0 comments on commit 8b5073f

Please sign in to comment.