Skip to content

Commit

Permalink
Fix the individual request rate-limit (#694)
Browse files Browse the repository at this point in the history
* Fix the individual request rate-limit

This fixes the first problem raised in #693

---------

Signed-off-by: nexy7574 <[email protected]>
Co-authored-by: Gnuxie <[email protected]>
  • Loading branch information
nexy7574 and Gnuxie authored Jan 19, 2025
1 parent 2300b1e commit 0e2f81e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,18 @@ function patchMatrixClientForRetry() {
return cb(...result);
} catch (err) {
// Need to retry.
let retryAfterMs = attempt * attempt * REQUEST_RETRY_BASE_DURATION_MS;
if ("retry_after_ms" in err) {
try {
retryAfterMs = Number.parseInt(err.retry_after_ms, 10);
} catch (ex) {
// Use default value.
const retryAfterMs = (() => {
if (err instanceof MatrixError && err.retryAfterMs !== undefined) {
return err.retryAfterMs;
} else {
LogService.error(
"Draupnir.client",
"Unable to extract retry_after_ms from error, using fallback to create retry duration",
err
);
return attempt * attempt * REQUEST_RETRY_BASE_DURATION_MS;
}
}
})();
LogService.debug(
"Draupnir.client",
`Waiting ${retryAfterMs}ms before retrying ${params.method} ${params.uri}`
Expand Down

0 comments on commit 0e2f81e

Please sign in to comment.