Skip to content

Fix GitHub API timeouts#6

Merged
amkayondo merged 3 commits intomainfrom
copilot/fix-timeouts
Feb 22, 2026
Merged

Fix GitHub API timeouts#6
amkayondo merged 3 commits intomainfrom
copilot/fix-timeouts

Conversation

Copy link
Contributor

Copilot AI commented Feb 22, 2026

GitHub API calls had no per-request timeout, allowing requests to hang indefinitely. API routes also lacked maxDuration exports, causing premature termination on serverless platforms.

Changes

  • lib/github.ts — Add AbortSignal.timeout(30s) to ghFetch() via a GITHUB_API_TIMEOUT_MS constant
  • src/scraper.js — Add request.timeout: 30_000 to the Octokit client config
  • API routes — Export maxDuration on all route handlers:
    • /api/scrape → 60s (multiple sequential API calls + courtesy delays)
    • /api/export/json, /api/export/csv → 30s
// lib/github.ts
const GITHUB_API_TIMEOUT_MS = 30_000;

const res = await fetch(url, {
  headers: headers(),
  signal: AbortSignal.timeout(GITHUB_API_TIMEOUT_MS),
});

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@netlify
Copy link

netlify bot commented Feb 22, 2026

Deploy Preview for gitfastnow ready!

Name Link
🔨 Latest commit 121b95d
🔍 Latest deploy log https://app.netlify.com/projects/gitfastnow/deploys/699a72312fe60500088017d9
😎 Deploy Preview https://deploy-preview-6--gitfastnow.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI changed the title [WIP] Fix timeouts in application Fix GitHub API timeouts Feb 22, 2026
Copilot AI requested a review from amkayondo February 22, 2026 03:04
@amkayondo amkayondo marked this pull request as ready for review February 22, 2026 03:12
Copilot AI review requested due to automatic review settings February 22, 2026 03:12
@amkayondo amkayondo merged commit 98769f5 into main Feb 22, 2026
4 checks passed
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 adds explicit timeouts to GitHub API calls and adjusts Next.js route handler time limits to reduce hanging requests and premature termination in serverless environments.

Changes:

  • Add a per-request timeout to ghFetch() (via AbortSignal.timeout) for GitHub API calls.
  • Configure Octokit with a 30s request timeout in the standalone scraper.
  • Export maxDuration from API route handlers to align with expected execution time.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/github.ts Adds a 30s per-request timeout to fetch() calls used for GitHub API access.
src/scraper.js Adds a 30s request timeout to the Octokit client used by the CLI scraper.
app/api/scrape/route.ts Sets maxDuration = 60 to allow longer-running scrape requests.
app/api/export/json/route.ts Sets maxDuration = 30 for JSON export route.
app/api/export/csv/route.ts Sets maxDuration = 30 for CSV export route.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +47 to 51
const res = await fetch(url, {
headers: headers(),
signal: AbortSignal.timeout(GITHUB_API_TIMEOUT_MS),
});

Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

fetch() will throw on timeout (AbortError) or other network errors, which bypasses the current retry loop entirely. Since this PR introduces timeouts, consider wrapping the fetch() call in a try/catch and retrying (or at least converting AbortError into a clearer error) so a transient timeout doesn’t immediately fail the whole scrape.

Suggested change
const res = await fetch(url, {
headers: headers(),
signal: AbortSignal.timeout(GITHUB_API_TIMEOUT_MS),
});
let res: Response;
try {
res = await fetch(url, {
headers: headers(),
signal: AbortSignal.timeout(GITHUB_API_TIMEOUT_MS),
});
} catch (err) {
const isAbortError =
err instanceof Error && err.name === "AbortError";
if (attempt < maxRetries) {
// Simple backoff for transient network/timeout errors.
const backoffMs = 1000 * (attempt + 1);
await sleep(backoffMs);
continue;
}
const baseMessage = isAbortError
? `GitHub API request timed out after ${GITHUB_API_TIMEOUT_MS}ms`
: "GitHub API request failed";
const detail =
err instanceof Error && err.message
? `: ${err.message}`
: "";
throw new Error(`${baseMessage}${detail} (${url})`);
}

Copilot uses AI. Check for mistakes.
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