Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a timeout for downloading razor telemetry #6622

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/packageManager/fileDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ async function downloadFile(
agent: getProxyAgent(url, proxy, strictSSL),
port: url.port,
rejectUnauthorized: strictSSL,
timeout: 5 * 60 * 1000, // timeout is in milliseconds
davidwengier marked this conversation as resolved.
Show resolved Hide resolved
};

const buffers: any[] = [];
Expand Down Expand Up @@ -129,6 +130,10 @@ async function downloadFile(
});
});

request.on('timeout', () => {
request.destroy(new Error(`Timed out trying to download ${urlString}.`));
});

request.on('error', (err) => {
reject(new NestedError(`Request error: ${err.message || 'NONE'}`, err));
});
Expand Down
13 changes: 12 additions & 1 deletion src/razor/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as path from 'path';
import * as vscode from 'vscode';
import * as vscodeapi from 'vscode';
import * as util from '../../common';
import { ExtensionContext } from 'vscode';
import { BlazorDebugConfigurationProvider } from './blazorDebug/blazorDebugConfigurationProvider';
import { CodeActionsHandler } from './codeActions/codeActionsHandler';
Expand Down Expand Up @@ -99,17 +100,27 @@ export async function activate(
// Save user's DOTNET_ROOT env-var value so server can recover the user setting when needed
env.DOTNET_ROOT_USER = process.env.DOTNET_ROOT ?? 'EMPTY';

let telemetryExtensionDllPath = '';
// Set up DevKit environment for telemetry
if (csharpDevkitExtension) {
await setupDevKitEnvironment(env, csharpDevkitExtension, logger);
maryamariyan marked this conversation as resolved.
Show resolved Hide resolved

const telemetryExtensionPath = path.join(
util.getExtensionPath(),
'.razortelemetry',
'Microsoft.VisualStudio.DevKit.Razor.dll'
);
if (await util.fileExists(telemetryExtensionPath)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this all out just because of the await

telemetryExtensionDllPath = telemetryExtensionPath;
}
}

const languageServerClient = new RazorLanguageServerClient(
vscodeType,
languageServerDir,
razorTelemetryReporter,
vscodeTelemetryReporter,
csharpDevkitExtension !== undefined,
telemetryExtensionDllPath,
env,
dotnetInfo.path,
logger
Expand Down
11 changes: 3 additions & 8 deletions src/razor/src/razorLanguageServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as path from 'path';
import * as cp from 'child_process';
import { EventEmitter } from 'events';
import * as util from '../../common';
import * as vscode from 'vscode';
import { RequestHandler, RequestType } from 'vscode-jsonrpc';
import { GenericNotificationHandler, InitializeResult, LanguageClientOptions, State } from 'vscode-languageclient';
Expand Down Expand Up @@ -40,7 +38,7 @@ export class RazorLanguageServerClient implements vscode.Disposable {
private readonly languageServerDir: string,
private readonly razorTelemetryReporter: RazorTelemetryReporter,
private readonly vscodeTelemetryReporter: TelemetryReporter,
private readonly isCSharpDevKitActivated: boolean,
private readonly telemetryExtensionDllPath: string,
private readonly env: NodeJS.ProcessEnv,
private readonly dotnetExecutablePath: string,
private readonly logger: RazorLogger
Expand Down Expand Up @@ -249,13 +247,10 @@ export class RazorLanguageServerClient implements vscode.Disposable {
args.push('--UpdateBuffersForClosedDocuments');
args.push('true');

if (this.isCSharpDevKitActivated) {
if (this.telemetryExtensionDllPath.length > 0) {
args.push('--telemetryLevel', this.vscodeTelemetryReporter.telemetryLevel);
args.push('--sessionId', getSessionId());
args.push(
'--telemetryExtensionPath',
path.join(util.getExtensionPath(), '.razortelemetry', 'Microsoft.VisualStudio.DevKit.Razor.dll')
);
args.push('--telemetryExtensionPath', this.telemetryExtensionDllPath);
}
}

Expand Down
Loading