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

034a5f3aa416fa858a86f62513a9402920be8ec8

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
1 files changed, +11 -5Showing whitespace changes
src/endpoints/extensions.js+11 -5
@@ -8,6 +8,11 @@ import { CheckRepoActions, default as simpleGit } from 'simple-git';
88import { PUBLIC_DIRECTORIES } from '../constants.js';
99
1010/**
11+ * @type {Partial<import('simple-git').SimpleGitOptions>}
12+ */
13+const OPTIONS = Object.freeze({ timeout: { block: 5 * 60 * 1000 } });
14+
15+/**
1116 * This function extracts the extension information from the manifest file.
1217 * @param {string} extensionPath - The path of the extension folder
1318 * @returns {Promise<Object>} - Returns the manifest data as an object
@@ -30,7 +35,7 @@ async function getManifest(extensionPath) {
3035 * @returns {Promise<Object>} - Returns the extension information as an object
3136 */
3237async function checkIfRepoIsUpToDate(extensionPath) {
3338 const git = simpleGit({ baseDir: extensionPath, ...OPTIONS });
3439 await git.fetch('origin');
3540 const currentBranch = await git.branch();
3641 const currentCommitHash = await git.revparse(['HEAD']);
@@ -71,6 +76,7 @@ router.post('/install', async (request, response) => {
7176 }
7277
7378 try {
79+ // No timeout for cloning, as it may take a while depending on the repo size
7480 const git = simpleGit();
7581
7682 // make sure the third-party directory exists
@@ -144,7 +150,7 @@ router.post('/update', async (request, response) => {
144150 }
145151
146152 const { isUpToDate, remoteUrl } = await checkIfRepoIsUpToDate(extensionPath);
147153 const git = simpleGit({ baseDir: extensionPath, ...OPTIONS });
148154 const isRepo = await git.checkIsRepo(CheckRepoActions.IS_REPO_ROOT);
149155 if (!isRepo) {
150156 throw new Error(`Directory is not a Git repository at ${extensionPath}`);
@@ -187,7 +193,7 @@ router.post('/branches', async (request, response) => {
187193 return response.status(404).send(`Directory does not exist at ${extensionPath}`);
188194 }
189195
190196 const git = simpleGit({ baseDir: extensionPath, ...OPTIONS });
191197 // Unshallow the repository if it is shallow
192198 const isShallow = await git.revparse(['--is-shallow-repository']) === 'true';
193199 if (isShallow) {
@@ -232,7 +238,7 @@ router.post('/switch', async (request, response) => {
232238 return response.status(404).send(`Directory does not exist at ${extensionPath}`);
233239 }
234240
235241 const git = simpleGit({ baseDir: extensionPath, ...OPTIONS });
236242 const branches = await git.branchLocal();
237243
238244 if (String(branch).startsWith('origin/')) {
@@ -339,7 +345,7 @@ router.post('/version', async (request, response) => {
339345 return response.status(404).send(`Directory does not exist at ${extensionPath}`);
340346 }
341347
342348 const git = simpleGit({ baseDir: extensionPath, ...OPTIONS });
343349 let currentCommitHash;
344350 try {
345351 const isRepo = await git.checkIsRepo(CheckRepoActions.IS_REPO_ROOT);