From c544f512a33cfc37da14482cc1a8cb5fa1b6f21a Mon Sep 17 00:00:00 2001 From: AboMeezO Date: Sat, 13 Jun 2026 01:04:05 +0300 Subject: [PATCH] fix: prevent duplicate project starts --- electron/services/projectsManager.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/electron/services/projectsManager.js b/electron/services/projectsManager.js index 31f9863..64ddc7d 100644 --- a/electron/services/projectsManager.js +++ b/electron/services/projectsManager.js @@ -18,6 +18,7 @@ import { const numCPUs = os.cpus().length; const runningRuntimes = {}; +const startLocks = new Map(); const logHistory = {}; const statusListeners = new Set(); const listListeners = new Set(); @@ -238,6 +239,22 @@ export const writeToProcess = (id, data) => { //============================{Starts a Project}============================= export const startProject = async (id) => { + const key = String(id); + const existingStart = startLocks.get(key); + if (existingStart) return existingStart; + + const startPromise = startProjectUnlocked(id); + startLocks.set(key, startPromise); + try { + return await startPromise; + } finally { + if (startLocks.get(key) === startPromise) { + startLocks.delete(key); + } + } +}; + +const startProjectUnlocked = async (id) => { const project = await getProjectById(id); if (!project) throw new Error("Project not found");