fix: add max delay to retries#42
Conversation
Summary of ChangesHello @pedrocrvz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the retry mechanism by introducing a Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a maxDelay option to cap the exponential backoff delay in the retry mechanism, which is a useful addition for controlling retry behavior. However, a potential Denial of Service vulnerability has been identified because the maxDelay cap is not applied to the 'fixed' backoff strategy. It is recommended to apply maxDelay to all backoff strategies to enhance robustness. Additionally, there's an inconsistency in the default value for maxDelay between the implementation and the documentation that needs to be aligned.
| const code = (error as { code?: number }).code; | ||
| if (attempt < max && code !== undefined && errorCodes.includes(code)) { | ||
| const wait = backoff === 'exponential' ? delay * 2 ** attempt : delay; | ||
| const wait = backoff === 'exponential' ? Math.min(delay * 2 ** attempt, maxDelay) : delay; |
There was a problem hiding this comment.
The maxDelay parameter caps the retry delay for the 'exponential' backoff strategy, but it is not applied when the backoff strategy is 'fixed'. If a user can control the delay option, they could provide a very large value, causing the function to wait for an extended period. This can lead to resource exhaustion and a potential Denial of Service (DoS) vulnerability. The maxDelay cap should be applied to all backoff strategies.
| const wait = backoff === 'exponential' ? Math.min(delay * 2 ** attempt, maxDelay) : delay; | |
| const wait = Math.min(backoff === 'exponential' ? delay * 2 ** attempt : delay, maxDelay); |
| const errorCodes = options?.errorCodes ?? [SimulationFailedRpcError.code]; | ||
| const delay = options?.delay ?? 200; | ||
| const backoff = options?.backoff ?? 'exponential'; | ||
| const maxDelay = options?.maxDelay ?? 12_000; |
There was a problem hiding this comment.
There's an inconsistency in the default value for maxDelay. The implementation uses 12_000, but the JSDoc for the WithRetriesOptions interface (line 15) and the documentation in README.md and src/README.md all state the default is 10000. To ensure consistency between the code and its documentation, please update the default value here to match what's documented.
| const maxDelay = options?.maxDelay ?? 12_000; | |
| const maxDelay = options?.maxDelay ?? 10_000; |
No description provided.