-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
Fixed doPoll() spam calls at the start #236
Conversation
At the start of TradeOfferManager because of apiKey and the lastPoll default values, doPoll() was not being rate limited as it should.
I'm not sure I understand what you've changed. Under the old code, the poll will be skipped if:
Under your proposed code, the poll will be skipped if:
However, 0 will never be within 1000 ms of now. |
this._resetPollTimer(1000); | ||
return; | ||
} | ||
else if (this._lastPoll !== 0 && Date.now() - this._lastPoll < 1000) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be on same line as the closing curly brace.
return; | ||
} | ||
else if (this._lastPoll !== 0 && Date.now() - this._lastPoll < 1000) { | ||
this.emit('debug', '# Seconds Since Last Poll ' + (Date.now() - this._lastPoll)/1000 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super picky (sorry). This should be regular sentence capitalization, and the number sign is probably not needed:
"Seconds since last poll"
@@ -23,7 +23,13 @@ TradeOfferManager.prototype.doPoll = function(doFullUpdate) { | |||
return; | |||
} | |||
|
|||
if (!this.apiKey || Date.now() - this._lastPoll < 1000) { | |||
if(!this.apiKey){ | |||
this.emit('debug', 'No API Key, shouldn\'t poll' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also super picky (sorry, again) but the "k" in "key" shouldn't be capitalized.
I think the real problem is the They are stopped because the timer is being cleared and set again each time, but it seems inefficient to clear and set it again so many times. The Regarding the emit debugs they can be deleted or sintax corrected, I forgot that they were something I added, |
The problem is real, but I think @ric20007 doesn't understand it's root. Here it's called with argument of const now = Date.now();
const lastPoll = now - 1; // One ms ago
const timeSinceLastPoll = now - lastPoll;
setTimeout(doPoll, timeSinceLastPoll); My suggestion is to save the minimum poll interval into constant, then call See #237 for implementation. |
Why does |
@welwood08 I tried to keep the same logic as before while fixing the bug, in the comment above the |
Right, but I think the bug is actually that polling shouldn't be attempted at all until The code that sets |
At the start of TradeOfferManager because of apiKey and the lastPoll default values, doPoll() was not being rate limited as it should.