Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not create resend timer if exists #635

Merged
merged 3 commits into from May 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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