Skip to content

[KA-CHOW] fix(checkoutservice): Service checkoutservice is in critical health (score: 45) - #3

Open
HarshXAI wants to merge 1 commit into
mainfrom
kachow/heal-Service-checkoutservice-is-in-critical-h-1771741481204
Open

HarshXAI wants to merge 1 commit into
mainfrom
kachow/heal-Service-checkoutservice-is-in-critical-h-1771741481204

Conversation

@HarshXAI

Copy link
Copy Markdown
Owner

🔧 KA-CHOW Self-Healing Patch

Service: checkoutservice
Issue type: Service checkoutservice is in critical health (score: 45)

What changed

The code was updated to include an AbortController to handle request timeouts, ensuring that requests do not hang indefinitely. A timeout of 10 seconds was set. An exponential backoff retry mechanism was implemented, allowing up to 3 retries with increasing delays between attempts. Proper error handling was added to log errors and rethrow them when necessary. This ensures that transient errors and network issues are managed effectively, improving the service's reliability.

Patch

async function fetchWithRetry(url: string, options: RequestInit, retries = 3): Promise<Response> {
  const delay = (ms: number) => new Promise(res => setTimeout(res, ms));
  const exponentialBackoff = (attempt: number) => Math.pow(2, attempt) * 100;

  for (let attempt = 0; attempt <= retries; attempt++) {
    const controller = new AbortController();
    const timeoutId = setTimeout(() => controller.abort(), 10000);
    try {
      const response = await fetch(url, { ...options, signal: controller.signal });
      clearTimeout(timeoutId);
      if (!response.ok) {
        throw new Error(`Request failed with status ${response.status}`);
      }
      return response;
    } catch (error) {
      clearTimeout(timeoutId);
      console.error(`Attempt ${attempt + 1} failed:`, error);
      if (attempt < retries) {
        await delay(exponentialBackoff(attempt));
      } else {
        throw error;
      }
    }
  }
  throw new Error('Failed to fetch after retries');
}

Auto-generated by KA-CHOW — review before merging

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.

1 participant