From 941797359f6554ac16a2e478047aabd5cbc0404b Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Fri, 4 Aug 2023 22:28:41 -0700 Subject: fix: :bug: solve EBUSY by polling --- extension/src/activation/environmentSetup.ts | 32 ++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'extension') diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index 8818c949..32dfa52f 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -226,15 +226,29 @@ export async function startContinuePythonServer() { // Run the executable console.log("Starting Continue server"); - const child = spawn(destination, { - detached: true, - stdio: "ignore", - }); - child.on("error", (err: any) => { - console.error("Failed to start subprocess.", err); - }); - - child.unref(); + let attempts = 0; + let maxAttempts = 5; + let delay = 1000; // Delay between each attempt in milliseconds + + const spawnChild = () => { + const child = spawn(destination, { + detached: true, + stdio: "ignore", + }); + + child.on("error", (err: any) => { + if (err.code === "EBUSY" && attempts < maxAttempts) { + attempts++; + console.log(`EBUSY error caught. Retrying attempt ${attempts}...`); + setTimeout(spawnChild, delay); + } else { + console.error("Failed to start subprocess.", err); + } + }); + child.unref(); + }; + + spawnChild(); // Write the current version of vscode extension to a file called server_version.txt fs.writeFileSync(serverVersionPath(), getExtensionVersion()); -- cgit v1.2.3-70-g09d2