-
Notifications
You must be signed in to change notification settings - Fork 31
fix: prevent negative timeout in RetryHandler causing IllegalArgumentException #2051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
- Add check for negative retry interval in retryRequest method - Set random delay between 1-10ms when retry interval is negative - Add unit tests for negative retry interval scenarios - Prevents IllegalArgumentException: timeout value is negative Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix IllegalArgumentException in RetryHandler retryRequest
fix: prevent negative timeout in RetryHandler causing IllegalArgumentException
Nov 14, 2025
baywet
requested changes
Nov 14, 2025
components/http/okHttp/src/main/java/com/microsoft/kiota/http/middleware/RetryHandler.java
Outdated
Show resolved
Hide resolved
Move the negative value handling from retryRequest to getRetryAfter method as suggested in code review. This ensures getRetryAfter never returns a negative value, making the API more robust. - Move check from retryRequest to getRetryAfter - Update test to verify getRetryAfter returns 1-10ms instead of -1 - Maintain same behavior: random delay between 1-10ms for negative values Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
baywet
reviewed
Nov 14, 2025
components/http/okHttp/src/test/java/com/microsoft/kiota/http/middleware/RetryHandlerTest.java
Outdated
Show resolved
Hide resolved
components/http/okHttp/src/test/java/com/microsoft/kiota/http/middleware/RetryHandlerTest.java
Outdated
Show resolved
Hide resolved
components/http/okHttp/src/main/java/com/microsoft/kiota/http/middleware/RetryHandler.java
Show resolved
Hide resolved
Replace Math.random() with Random.nextLong(10) for generating random delays between 1-10ms. This provides better control and clarity over the random value generation. - Add java.util.Random import - Create static RANDOM instance - Use RANDOM.nextLong(10) to generate values 0-9, then add 1 for 1-10ms range Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
baywet
approved these changes
Nov 14, 2025
…delay" This reverts commit f9c23ee.
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
|
adrian05-ms
approved these changes
Nov 14, 2025
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.

Fix RetryHandler negative timeout issue
Plan
getRetryAftercan return negative value causing IllegalArgumentExceptiongetRetryAfterto ensure minimum delay of 1-10ms when result is negativeProblem
The
RetryHandler.retryRequestmethod can fail withIllegalArgumentException: timeout value is negativewhengetRetryAfterreturns a negative value. This happens when:Solution
Set a minimum random delay between 1-10ms in the
getRetryAftermethod when the calculated value is less than 0, as specified in the issue requirements.Changes Made
getRetryAftermethod using Random.nextLong()getRetryAfterreturns 1-10ms instead of -1 when parsing failsVerification
Code Review
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.