fix(github): add a per-request timeout to all Octokit calls

Octokit v22 uses native fetch, which has no built-in timeout, so a stuck
GitHub request hung until the PR-status route's 12s overall budget fired —
and one slow request could consume the entire budget. Wrap fetch with an 8s
AbortSignal.timeout via a shared createOctokit() factory, and route the inline
Octokit instantiations through it too.
This commit is contained in:
Bohdan Triapitsyn
2026-06-29 01:56:56 +03:00
parent f45089ccce
commit e5773662b3
3 changed files with 30 additions and 9 deletions
+8 -8
View File
@@ -108,8 +108,8 @@ export function registerGitHubRoutes(app) {
if (ghToken !== null && !ghCliDisabled) {
try {
const { Octokit } = await import('@octokit/rest');
ghCliUser = await getGitHubUserSummary(new Octokit({ auth: ghToken }));
const { createOctokit } = await import('./octokit.js');
ghCliUser = await getGitHubUserSummary(createOctokit(ghToken));
} catch {
ghCliUser = null;
}
@@ -246,8 +246,8 @@ export function registerGitHubRoutes(app) {
return res.status(500).json({ error: 'Missing access_token from GitHub' });
}
const { Octokit } = await import('@octokit/rest');
const octokit = new Octokit({ auth: accessToken });
const { createOctokit } = await import('./octokit.js');
const octokit = createOctokit(accessToken);
const user = await getGitHubUserSummary(octokit);
setGitHubAuth({
@@ -283,8 +283,8 @@ export function registerGitHubRoutes(app) {
return res.status(404).json({ error: 'GitHub CLI account not found' });
}
const { Octokit } = await import('@octokit/rest');
const user = await getGitHubUserSummary(new Octokit({ auth: ghToken }));
const { createOctokit } = await import('./octokit.js');
const user = await getGitHubUserSummary(createOctokit(ghToken));
setGhCliActive(true);
const accounts = getGitHubAuthAccounts()
.map((account) => ({ ...account, current: false }))
@@ -319,8 +319,8 @@ export function registerGitHubRoutes(app) {
let ghCliUser = null;
if (ghToken) {
try {
const { Octokit } = await import('@octokit/rest');
ghCliUser = await getGitHubUserSummary(new Octokit({ auth: ghToken }));
const { createOctokit } = await import('./octokit.js');
ghCliUser = await getGitHubUserSummary(createOctokit(ghToken));
accounts = accounts.concat({
id: GH_CLI_ACCOUNT_ID,
user: ghCliUser,