From 72f60df30f0c05dd5fae38d89adaae69c132f619 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Thu, 19 Oct 2023 16:14:49 -0700 Subject: [PATCH] Fix timeout issue & Set environment correctly on windows - the shell option is needed for spawn to access windows shell commands, exec does this by default but exec does not capture detailed output streams - fix a timeout where ms was used as seconds - note that you need to restart for telemetry notice to change --- vscode-dotnet-runtime-extension/package.json | 2 +- .../Acquisition/GlobalInstallerResolver.ts | 2 +- .../src/Acquisition/WinMacGlobalInstaller.ts | 10 +++++++- .../src/Utils/CommandExecutor.ts | 23 ++++++++----------- .../src/Utils/WebRequestWorker.ts | 2 +- vscode-dotnet-sdk-extension/package.json | 2 +- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/vscode-dotnet-runtime-extension/package.json b/vscode-dotnet-runtime-extension/package.json index baba532748..4842680f1f 100644 --- a/vscode-dotnet-runtime-extension/package.json +++ b/vscode-dotnet-runtime-extension/package.json @@ -57,7 +57,7 @@ "dotnetAcquisitionExtension.enableTelemetry": { "type": "boolean", "default": true, - "description": "Enable Telemetry for the .NET Runtime Install Tool" + "description": "Enable Telemetry for the .NET Runtime Install Tool. Restart VS Code to apply changes." }, "dotnetAcquisitionExtension.installTimeoutValue": { "type": "number", diff --git a/vscode-dotnet-runtime-library/src/Acquisition/GlobalInstallerResolver.ts b/vscode-dotnet-runtime-library/src/Acquisition/GlobalInstallerResolver.ts index 5d6d39be8e..da5724f8bf 100644 --- a/vscode-dotnet-runtime-library/src/Acquisition/GlobalInstallerResolver.ts +++ b/vscode-dotnet-runtime-library/src/Acquisition/GlobalInstallerResolver.ts @@ -375,7 +375,7 @@ Please report this issue so it can be remedied or investigated.`)); */ private async fetchJsonObjectFromUrl(url : string) { - const webWorker = this.customWebRequestWorker ? this.customWebRequestWorker : new WebRequestWorker(this.extensionState, this.eventStream, url, this.timeoutSecs, this.proxyUrl); + const webWorker = this.customWebRequestWorker ? this.customWebRequestWorker : new WebRequestWorker(this.extensionState, this.eventStream, url, this.timeoutSecs * 1000, this.proxyUrl); return webWorker.getCachedData(); } } diff --git a/vscode-dotnet-runtime-library/src/Acquisition/WinMacGlobalInstaller.ts b/vscode-dotnet-runtime-library/src/Acquisition/WinMacGlobalInstaller.ts index 1997d1ed36..99e1e4f9c3 100644 --- a/vscode-dotnet-runtime-library/src/Acquisition/WinMacGlobalInstaller.ts +++ b/vscode-dotnet-runtime-library/src/Acquisition/WinMacGlobalInstaller.ts @@ -13,7 +13,7 @@ import { FileUtilities } from '../Utils/FileUtilities'; import { IGlobalInstaller } from './IGlobalInstaller'; import { IAcquisitionWorkerContext } from './IAcquisitionWorkerContext'; import { VersionResolver } from './VersionResolver'; -import { DotnetAcquisitionDistroUnknownError, DotnetAcquisitionError, DotnetConflictingGlobalWindowsInstallError, DotnetUnexpectedInstallerOSError, OSXOpenNotAvailableError } from '../EventStream/EventStreamEvents'; +import { DotnetAcquisitionDistroUnknownError, DotnetAcquisitionError, DotnetConflictingGlobalWindowsInstallError, DotnetUnexpectedInstallerOSError, OSXOpenNotAvailableError, SuppressedAcquisitionError } from '../EventStream/EventStreamEvents'; import { ICommandExecutor } from '../Utils/ICommandExecutor'; import { CommandExecutor } from '../Utils/CommandExecutor'; import exp = require('constants'); @@ -125,6 +125,14 @@ We cannot verify .NET is safe to download at this time. Please try again later.` } await this.webWorker.downloadFile(installerUrl, installerPath); + try + { + fs.chmodSync(installerPath, 0o744); + } + catch(error : any) + { + this.acquisitionContext.eventStream.post(new SuppressedAcquisitionError(error, `Failed to chmod +x on ${installerPath}.`)); + } return installerPath; } diff --git a/vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts b/vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts index 57491d5d83..37fee3c96b 100644 --- a/vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts +++ b/vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts @@ -114,7 +114,7 @@ Please install the .NET SDK manually by following https://learn.microsoft.com/en { if(!options) { - options = {cwd : path.resolve(__dirname)}; + options = {cwd : path.resolve(__dirname), shell: os.platform() === 'win32'}; } const splitCommands : string[] = command.split('&&'); @@ -226,15 +226,14 @@ out: ${commandResult.stdout} err: ${commandResult.stderr}.`)); const setSystemVariable = `setx ${variable} "${value}"`; try { - environmentEditExitCode = environmentEditExitCode || Number((await this.execute(setShellVariable))[0]); - environmentEditExitCode = environmentEditExitCode || Number((await this.execute(setSystemVariable))[0]); + const shellEditResponse = await this.execute(setShellVariable); + environmentEditExitCode += Number(shellEditResponse[0]); + const systemEditResponse = await this.execute(setSystemVariable) + environmentEditExitCode += Number(systemEditResponse[0]); } catch(error) { - if(failureWarningMessage) - { - new WindowDisplayWorker().showWarningMessage(failureWarningMessage, () => {/* No Callback */}, ); - } + environmentEditExitCode = 1 } } else @@ -242,18 +241,16 @@ out: ${commandResult.stdout} err: ${commandResult.stderr}.`)); const setVariable = `${variable}=${value} && export ${variable}` try { - environmentEditExitCode = environmentEditExitCode || Number((await this.execute(setVariable))[0]);; + const environmentEditResponse = await this.execute(setVariable) + environmentEditExitCode += Number(environmentEditResponse[0]); } catch(error) { - if(failureWarningMessage) - { - new WindowDisplayWorker().showWarningMessage(failureWarningMessage, () => {/* No Callback */}, ); - } + environmentEditExitCode = 1; } } - if(environmentEditExitCode && failureWarningMessage) + if(environmentEditExitCode !== 0 && failureWarningMessage) { new WindowDisplayWorker().showWarningMessage(failureWarningMessage, () => {/* No Callback */}, ); } diff --git a/vscode-dotnet-runtime-library/src/Utils/WebRequestWorker.ts b/vscode-dotnet-runtime-library/src/Utils/WebRequestWorker.ts index 2d27d64055..be619b52d2 100644 --- a/vscode-dotnet-runtime-library/src/Utils/WebRequestWorker.ts +++ b/vscode-dotnet-runtime-library/src/Utils/WebRequestWorker.ts @@ -210,7 +210,7 @@ export class WebRequestWorker ...(keepAlive && {headers: { 'Connection': 'keep-alive' }}), ...(this.proxyEnabled() && {proxy : false}), ...(this.proxyEnabled() && {httpsAgent : this.proxyAgent}), - ...furtherOptions, + ...furtherOptions }; return options; diff --git a/vscode-dotnet-sdk-extension/package.json b/vscode-dotnet-sdk-extension/package.json index aec2ff37c3..7dc9ac279f 100644 --- a/vscode-dotnet-sdk-extension/package.json +++ b/vscode-dotnet-sdk-extension/package.json @@ -57,7 +57,7 @@ "dotnetSDKAcquisitionExtension.enableTelemetry": { "type": "boolean", "default": true, - "description": "Enable Telemetry for the .NET SDK Install Tool." + "description": "Enable Telemetry for the .NET SDK Install Tool. Restart VS Code to apply changes." }, "dotnetSDKAcquisitionExtension.installTimeoutValue": { "type": "number",