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

add unref to setTimeout to prevent hanging #13

Merged
merged 1 commit into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dist/RateLimit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class RateLimit {
console.log('starting resetTimeout for exceeded limit' + this._seconds * 1000, this.toString());
}
this.resetTimeout = setTimeout(() => { this.reset(); }, this._seconds * 1000);
this.resetTimeout.unref();
}
}
notifyLimiters() {
Expand Down
2 changes: 2 additions & 0 deletions dist/RateLimiter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,15 @@ class RateLimiter {
if (this.queue.length !== 0) {
const factorForEqualRights = Math.floor(Math.random() * 100);
this.intervalProcessQueue = setInterval(() => { this.processBurstQueue(); }, 1000 + factorForEqualRights);
this.intervalProcessQueue.unref();
}
}
refreshSpreadLimiter() {
this.clearTimeoutAndInterval();
this.intervalNextSpreadExecution = setInterval(() => {
this.processSpreadLimitInterval();
}, this.getSpreadInterval());
this.intervalNextSpreadExecution.unref();
}
execute(fn, onSuccess, onError) {
try {
Expand Down
4 changes: 3 additions & 1 deletion dist/RiotRateLimiter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class RiotRateLimiter {
this.limitersPerPlatformId[platformId] = {};
}
if (!this.limitersPerPlatformId[platformId][apiMethod]) {
console.log('creating sync rate limimter for ', platformId, apiMethod);
if (this.debug) {
console.log('creating sync rate limimter for ', platformId, apiMethod);
}
this.limitersPerPlatformId[platformId][apiMethod] = new RateLimiter_1.RateLimiter({
limits: [RateLimiter_1.RateLimiter.createSyncRateLimit(this.debug)],
strategy: this.strategy,
Expand Down
1 change: 1 addition & 0 deletions src/RateLimit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export class RateLimit implements Comparable, RateLimitOptions {
}
// NOTE: using timeout since interval is not testable for some reason with node-ts and sinon!?
this.resetTimeout = setTimeout(() => {this.reset()}, this._seconds * 1000)
this.resetTimeout.unref()
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/RateLimiter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ export class RateLimiter {
// rare case propably
const factorForEqualRights = Math.floor(Math.random() * 100)
this.intervalProcessQueue = setInterval(() => {this.processBurstQueue()}, 1000 + factorForEqualRights)
this.intervalProcessQueue.unref()
}
}

Expand All @@ -412,6 +413,7 @@ export class RateLimiter {
this.intervalNextSpreadExecution = setInterval(() => {
this.processSpreadLimitInterval()
}, this.getSpreadInterval())
this.intervalNextSpreadExecution.unref()
}

/**
Expand Down