Skip to content

Conversation

@Claimundefine
Copy link
Contributor

What

HttpRequestMessage cannot be used multiple times after failure - Moving initialization inside loop and adding more descriptive error message.

Checklist

  • Contains customer facing changes? Including API/behavior changes
  • Did you add sufficient unit test and/or integration test coverage for this PR?
    • If not, please explain why it is not required

References

JIRA:

Test & Review

Open questions / Follow-ups

Copilot AI review requested due to automatic review settings November 18, 2025 17:22
@Claimundefine Claimundefine requested review from a team as code owners November 18, 2025 17:22
Copy link

Copilot AI left a 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 HttpRequestMessage creation 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
{
Copy link

Copilot AI Nov 18, 2025

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.

Suggested change
{
{
// HttpRequestMessage cannot be reused, so we must create a new one on each retry attempt.

Copilot uses AI. Check for mistakes.
{
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}");
Copy link

Copilot AI Nov 18, 2025

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.

Suggested change
$"Failed to fetch token from server: {e.GetType().FullName} - {e.Message}");
$"Failed to fetch token from server: {e.GetType().FullName} - {e.Message}", e);

Copilot uses AI. Check for mistakes.
Copy link
Member

@rayokota rayokota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Claimundefine , LGTM

@sonarqube-confluent
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants