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';
8import { PUBLIC_DIRECTORIES } from '../constants.js';8import { PUBLIC_DIRECTORIES } from '../constants.js';
99
10/**10/**
11 * @type {Partial<import('simple-git').SimpleGitOptions>}
12 */
13const 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 folder17 * @param {string} extensionPath - The path of the extension folder
13 * @returns {Promise<Object>} - Returns the manifest data as an object18 * @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 object35 * @returns {Promise<Object>} - Returns the extension information as an object
31 */36 */
32async function checkIfRepoIsUpToDate(extensionPath) {37async 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 }
7277
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();
7581
76 // make sure the third-party directory exists82 // make sure the third-party directory exists
@@ -144,7 +150,7 @@ router.post('/update', async (request, response) => {
144 }150 }
145151
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 }
189195
190 const git = simpleGit({ baseDir: extensionPath });196 const git = simpleGit({ baseDir: extensionPath, ...OPTIONS });
191 // Unshallow the repository if it is shallow197 // 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 }
234240
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();
237243
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 }
341347
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);