Skip to content

Commit

Permalink
do not create resend timer if exists (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Wolff committed May 27, 2020
1 parent d69b388 commit aa86981
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Library/Sender.ts
Expand Up @@ -33,6 +33,7 @@ class Sender {
private _onError: (error: Error) => void;
private _enableDiskRetryMode: boolean;
private _numConsecutiveFailures: number;
private _resendTimer: NodeJS.Timer | null;
protected _resendInterval: number;
protected _maxBytesOnDisk: number;

Expand All @@ -44,6 +45,7 @@ class Sender {
this._resendInterval = Sender.WAIT_BETWEEN_RESEND;
this._maxBytesOnDisk = Sender.MAX_BYTES_ON_DISK;
this._numConsecutiveFailures = 0;
this._resendTimer = null;

if (!Sender.OS_PROVIDES_FILE_PROTECTION) {
// Node's chmod levels do not appropriately restrict file access on Windows
Expand Down Expand Up @@ -135,7 +137,13 @@ class Sender {
if (this._enableDiskRetryMode) {
// try to send any cached events if the user is back online
if (res.statusCode === 200) {
setTimeout(() => this._sendFirstFileOnDisk(), this._resendInterval).unref();
if (!this._resendTimer) {
this._resendTimer = setTimeout(() => {
this._resendTimer = null;
this._sendFirstFileOnDisk()
}, this._resendInterval);
this._resendTimer.unref();
}
// store to disk in case of burst throttling
} else if (
res.statusCode === 408 || // Timeout
Expand Down

0 comments on commit aa86981

Please sign in to comment.