Fix the individual request rate-limit (#694)

* Fix the individual request rate-limit

This fixes the first problem raised in #693

---------

Signed-off-by: nexy7574 <git@nexy7574.co.uk>
Co-authored-by: Gnuxie <50846879+Gnuxie@users.noreply.github.com>
This commit is contained in:
nexy7574
2025-01-19 18:32:55 +00:00
committed by GitHub
co-authored by Gnuxie
parent 2300b1eef3
commit 0e2f81e971
+11 -7
View File
@@ -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}`