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