Skip to content

Commit

Permalink
Merge pull request #11 from bitcoinerlab/fix/throttling-infinite-loop
Browse files Browse the repository at this point in the history
Ensure throttling is disabled after final task to prevent infinite loops
  • Loading branch information
landabaso authored Sep 10, 2024
2 parents 2fff553 + db2293f commit f1d89d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@bitcoinerlab/explorer",
"description": "Bitcoin Blockchain Explorer: Client Interface featuring Esplora and Electrum Implementations.",
"homepage": "https://github.com/bitcoinerlab/explorer",
"version": "0.3.0",
"version": "0.3.1",
"author": "Jose-Luis Landabaso",
"license": "MIT",
"prettier": "@bitcoinerlab/configs/prettierConfig.json",
Expand Down
14 changes: 13 additions & 1 deletion src/requestQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,24 @@ export class RequestQueue {
hardErrorAttempts >= this.maxAttemptsForHardErrors - 1
) {
this.concurrentTasks--;
//Fetch failed. Now this error must be rethrown.
//Befor that, if this was the last task, disable throttling after
//unthrottleAfterTime to prevent an infinite loop in the while() on
//the next call. See below: while(mustThrottle === true)...
if (this.concurrentTasks === 0) {
if (this.unthrottleTimeout) clearTimeout(this.unthrottleTimeout);
this.unthrottleTimeout = setTimeout(() => {
this.mustThrottle = false;
this.unthrottleTimeout = undefined;
}, this.unthrottleAfterTime);
}
console.warn(
`Max attempts reached soft ${softErrorAttempts + 1} / hard ${
hardErrorAttempts + 1
} - rethrowing error. Consider reducing rate limits and/or increasing maxAttemptsForSoftErrors & maxAttemptsForSoftErrors.`
);
throw error; //not going to try again - rethrow original error
//Not going to try again - rethrow original error
throw error;
} else {
softErrorAttempts++;
hardErrorAttempts++;
Expand Down

0 comments on commit f1d89d4

Please sign in to comment.