From ef5bf5b8deaa04bd37f2911b49cb18fe52a10fa7 Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 26 Jan 2024 13:45:56 -0900 Subject: [PATCH] Override connect timeout --- src/remote.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/remote.ts b/src/remote.ts index 5561aca3..2af8fa9e 100644 --- a/src/remote.ts +++ b/src/remote.ts @@ -273,17 +273,35 @@ export class Remote { [`${authorityParts[1]}`]: agent.operating_system, } + // VS Code ignores the timeout in the SSH config with a default of 15 + // seconds, which can be too short in the case where we wait for startup + // scripts. For now we hardcode a longer value. + const connectTimeout = 1800 + let settingsContent = "{}" try { settingsContent = await fs.readFile(this.storage.getUserSettingsPath(), "utf8") } catch (ex) { // Ignore! It's probably because the file doesn't exist. } - const parsed = jsonc.parse(settingsContent) + + // The parser can return undefined if the file is blank. + const parsed = jsonc.parse(settingsContent) || {} parsed["remote.SSH.remotePlatform"] = remotePlatforms - const edits = jsonc.modify(settingsContent, ["remote.SSH.remotePlatform"], remotePlatforms, {}) + parsed["remote.SSH.connectTimeout"] = connectTimeout + + settingsContent = jsonc.applyEdits( + settingsContent, + jsonc.modify(settingsContent, ["remote.SSH.remotePlatform"], remotePlatforms, {}), + ) + + settingsContent = jsonc.applyEdits( + settingsContent, + jsonc.modify(settingsContent, ["remote.SSH.connectTimeout"], connectTimeout, {}), + ) + try { - await fs.writeFile(this.storage.getUserSettingsPath(), jsonc.applyEdits(settingsContent, edits)) + await fs.writeFile(this.storage.getUserSettingsPath(), settingsContent) } catch (ex) { // The user will just be prompted instead, which is fine! // If a user's settings.json is read-only, then we can't write to it.