Fix TimeoutOverflowWarning in retry strategy#568
Merged
polRk merged 2 commits intoydb-platform:mainfrom Mar 11, 2026
Merged
Conversation
Contributor
Author
|
Issue где описан подобный случай ошибки - #536 |
Replace exponential(ms) with backoff(base, max) in defaultRetryConfig and defaultStreamRetryConfig. exponential() grows unbounded and reaches Infinity after enough retries, causing Node.js to emit TimeoutOverflowWarning and reset setTimeout to 1ms — a busy loop. New caps: - OVERLOADED / RESOURCE_EXHAUSTED: backoff(1000, 60_000) - default / stream CANCELLED|UNAVAILABLE: backoff(10, 30_000) Add tests verifying the computed delay never exceeds the configured max.
7a16410 to
83c864a
Compare
polRk
requested changes
Mar 11, 2026
Member
polRk
left a comment
There was a problem hiding this comment.
Нужно еще файлик changeset создать, для версионирования
packages/retry/src/index.ts
Outdated
|
|
||
| if (ctx.error instanceof YDBError && ctx.error.code === StatusIds_StatusCode.OVERLOADED) { | ||
| return exponential(1000)(ctx, cfg) | ||
| return backoff(1000, 60_000)(ctx, cfg) |
Member
There was a problem hiding this comment.
Нужно вынести эти магические констнты вверх файла.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause:
In packages/retry/src/index.ts, defaultRetryConfig uses exponential(ms) which computes 2^attempt * ms.
exponential(ms)вычисляет2^attempt * msбез ограничения сверху. После достаточного числа попыток результат становитсяInfinity, которое передаётся вsetTimeout. Node.js не умеет работать с таким значением, выбрасываетTimeoutOverflowWarningи сбрасывает задержку до 1 мс — retry-цикл превращается в busy loop.Исправление: заменить на уже существующую функцию
backoff(base, max)изstrategy.ts, которая ограничивает результат черезMath.min(2^attempt * base, max).OVERLOADED/RESOURCE_EXHAUSTED→backoff(1000, 60_000)CANCELLED|UNAVAILABLE→backoff(10, 30_000)Добавлены тесты, которые проверяют что задержка никогда не превышает заданный максимум.