Skip to content

Commit

Permalink
Override connect timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
code-asher committed Jan 26, 2024
1 parent d775e37 commit ef5bf5b
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ef5bf5b

Please sign in to comment.