fix: timeout git process after 5 minutes of inactivity (#4673) * fix: timeout git process after 10 seconds of inactivity * fix: increase git process timeout to 10 minutes * 10->5 min, remove timeout from install
Signed| @@ -8,6 +8,11 @@ import { CheckRepoActions, default as simpleGit } from 'simple-git'; | ||
| 8 | 8 | import { PUBLIC_DIRECTORIES } from '../constants.js'; |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | + * @type {Partial<import('simple-git').SimpleGitOptions>} | |
| 12 | + */ | |
| 13 | +const OPTIONS = Object.freeze({ timeout: { block: 5 * 60 * 1000 } }); | |
| 14 | + | |
| 15 | +/** | |
| 11 | 16 | * This function extracts the extension information from the manifest file. |
| 12 | 17 | * @param {string} extensionPath - The path of the extension folder |
| 13 | 18 | * @returns {Promise<Object>} - Returns the manifest data as an object |
| @@ -30,7 +35,7 @@ async function getManifest(extensionPath) { | ||
| 30 | 35 | * @returns {Promise<Object>} - Returns the extension information as an object |
| 31 | 36 | */ |
| 32 | 37 | async function checkIfRepoIsUpToDate(extensionPath) { |
| 33 | 38 | const git = simpleGit({ baseDir: extensionPath, ...OPTIONS }); |
| 34 | 39 | await git.fetch('origin'); |
| 35 | 40 | const currentBranch = await git.branch(); |
| 36 | 41 | const currentCommitHash = await git.revparse(['HEAD']); |
| @@ -71,6 +76,7 @@ router.post('/install', async (request, response) => { | ||
| 71 | 76 | } |
| 72 | 77 | |
| 73 | 78 | try { |
| 79 | + // No timeout for cloning, as it may take a while depending on the repo size | |
| 74 | 80 | const git = simpleGit(); |
| 75 | 81 | |
| 76 | 82 | // make sure the third-party directory exists |
| @@ -144,7 +150,7 @@ router.post('/update', async (request, response) => { | ||
| 144 | 150 | } |
| 145 | 151 | |
| 146 | 152 | const { isUpToDate, remoteUrl } = await checkIfRepoIsUpToDate(extensionPath); |
| 147 | 153 | const git = simpleGit({ baseDir: extensionPath, ...OPTIONS }); |
| 148 | 154 | const isRepo = await git.checkIsRepo(CheckRepoActions.IS_REPO_ROOT); |
| 149 | 155 | if (!isRepo) { |
| 150 | 156 | throw new Error(`Directory is not a Git repository at ${extensionPath}`); |
| @@ -187,7 +193,7 @@ router.post('/branches', async (request, response) => { | ||
| 187 | 193 | return response.status(404).send(`Directory does not exist at ${extensionPath}`); |
| 188 | 194 | } |
| 189 | 195 | |
| 190 | 196 | const git = simpleGit({ baseDir: extensionPath, ...OPTIONS }); |
| 191 | 197 | // Unshallow the repository if it is shallow |
| 192 | 198 | const isShallow = await git.revparse(['--is-shallow-repository']) === 'true'; |
| 193 | 199 | if (isShallow) { |
| @@ -232,7 +238,7 @@ router.post('/switch', async (request, response) => { | ||
| 232 | 238 | return response.status(404).send(`Directory does not exist at ${extensionPath}`); |
| 233 | 239 | } |
| 234 | 240 | |
| 235 | 241 | const git = simpleGit({ baseDir: extensionPath, ...OPTIONS }); |
| 236 | 242 | const branches = await git.branchLocal(); |
| 237 | 243 | |
| 238 | 244 | if (String(branch).startsWith('origin/')) { |
| @@ -339,7 +345,7 @@ router.post('/version', async (request, response) => { | ||
| 339 | 345 | return response.status(404).send(`Directory does not exist at ${extensionPath}`); |
| 340 | 346 | } |
| 341 | 347 | |
| 342 | 348 | const git = simpleGit({ baseDir: extensionPath, ...OPTIONS }); |
| 343 | 349 | let currentCommitHash; |
| 344 | 350 | try { |
| 345 | 351 | const isRepo = await git.checkIsRepo(CheckRepoActions.IS_REPO_ROOT); |