-
Notifications
You must be signed in to change notification settings - Fork 882
Ensure single use of HttpRequestMessage for token fetch #2544
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where HttpRequestMessage was being reused after failures in token fetch retries, which is not allowed. The request object initialization is moved inside the retry loop, and the error message is enhanced to include exception type information.
Key Changes
- Move
HttpRequestMessagecreation inside the retry loop to ensure a fresh instance per attempt - Enhance error message to include exception type alongside the message
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| for (int i = 0; i < maxRetries + 1; i++){ | ||
| try | ||
| { |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Creating a new HttpRequestMessage on every retry attempt may be inefficient if the request creation involves expensive operations. However, this is necessary since HttpRequestMessage cannot be reused. Consider documenting this behavior with a comment explaining why the request must be created inside the loop.
| { | |
| { | |
| // HttpRequestMessage cannot be reused, so we must create a new one on each retry attempt. |
| { | ||
| throw new Exception("Failed to fetch token from server: " + e.Message); | ||
| throw new Exception( | ||
| $"Failed to fetch token from server: {e.GetType().FullName} - {e.Message}"); |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider preserving the original exception's stack trace by using 'throw new Exception(..., e)' to include the inner exception. This would provide better diagnostic information while still customizing the error message.
| $"Failed to fetch token from server: {e.GetType().FullName} - {e.Message}"); | |
| $"Failed to fetch token from server: {e.GetType().FullName} - {e.Message}", e); |
rayokota
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Claimundefine , LGTM
|




What
HttpRequestMessage cannot be used multiple times after failure - Moving initialization inside loop and adding more descriptive error message.
Checklist
References
JIRA:
Test & Review
Open questions / Follow-ups