Skip to content

Commit 314bf8a

Browse files
committed
Add a timeout for telemetry downloading
1 parent 8c42eb1 commit 314bf8a

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/packageManager/fileDownloader.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ async function downloadFile(
6666
agent: getProxyAgent(url, proxy, strictSSL),
6767
port: url.port,
6868
rejectUnauthorized: strictSSL,
69+
timeout: 5 * 60 * 1000, // timeout is in milliseconds
6970
};
7071

7172
const buffers: any[] = [];
@@ -129,6 +130,10 @@ async function downloadFile(
129130
});
130131
});
131132

133+
request.on('timeout', () => {
134+
request.destroy(new Error(`Timed out trying to download ${urlString}.`));
135+
});
136+
132137
request.on('error', (err) => {
133138
reject(new NestedError(`Request error: ${err.message || 'NONE'}`, err));
134139
});

src/razor/src/extension.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as path from 'path';
77
import * as vscode from 'vscode';
88
import * as vscodeapi from 'vscode';
9+
import * as util from '../../common';
910
import { ExtensionContext } from 'vscode';
1011
import { BlazorDebugConfigurationProvider } from './blazorDebug/blazorDebugConfigurationProvider';
1112
import { CodeActionsHandler } from './codeActions/codeActionsHandler';
@@ -99,17 +100,27 @@ export async function activate(
99100
// Save user's DOTNET_ROOT env-var value so server can recover the user setting when needed
100101
env.DOTNET_ROOT_USER = process.env.DOTNET_ROOT ?? 'EMPTY';
101102

103+
let telemetryExtensionDllPath = '';
102104
// Set up DevKit environment for telemetry
103105
if (csharpDevkitExtension) {
104106
await setupDevKitEnvironment(env, csharpDevkitExtension, logger);
107+
108+
const telemetryExtensionPath = path.join(
109+
util.getExtensionPath(),
110+
'.razortelemetry',
111+
'Microsoft.VisualStudio.DevKit.Razor.dll'
112+
);
113+
if (await util.fileExists(telemetryExtensionPath)) {
114+
telemetryExtensionDllPath = telemetryExtensionPath;
115+
}
105116
}
106117

107118
const languageServerClient = new RazorLanguageServerClient(
108119
vscodeType,
109120
languageServerDir,
110121
razorTelemetryReporter,
111122
vscodeTelemetryReporter,
112-
csharpDevkitExtension !== undefined,
123+
telemetryExtensionDllPath,
113124
env,
114125
dotnetInfo.path,
115126
logger

src/razor/src/razorLanguageServerClient.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as path from 'path';
76
import * as cp from 'child_process';
87
import { EventEmitter } from 'events';
9-
import * as util from '../../common';
108
import * as vscode from 'vscode';
119
import { RequestHandler, RequestType } from 'vscode-jsonrpc';
1210
import { GenericNotificationHandler, InitializeResult, LanguageClientOptions, State } from 'vscode-languageclient';
@@ -40,7 +38,7 @@ export class RazorLanguageServerClient implements vscode.Disposable {
4038
private readonly languageServerDir: string,
4139
private readonly razorTelemetryReporter: RazorTelemetryReporter,
4240
private readonly vscodeTelemetryReporter: TelemetryReporter,
43-
private readonly isCSharpDevKitActivated: boolean,
41+
private readonly telemetryExtensionDllPath: string,
4442
private readonly env: NodeJS.ProcessEnv,
4543
private readonly dotnetExecutablePath: string,
4644
private readonly logger: RazorLogger
@@ -249,13 +247,10 @@ export class RazorLanguageServerClient implements vscode.Disposable {
249247
args.push('--UpdateBuffersForClosedDocuments');
250248
args.push('true');
251249

252-
if (this.isCSharpDevKitActivated) {
250+
if (this.telemetryExtensionDllPath.length > 0) {
253251
args.push('--telemetryLevel', this.vscodeTelemetryReporter.telemetryLevel);
254252
args.push('--sessionId', getSessionId());
255-
args.push(
256-
'--telemetryExtensionPath',
257-
path.join(util.getExtensionPath(), '.razortelemetry', 'Microsoft.VisualStudio.DevKit.Razor.dll')
258-
);
253+
args.push('--telemetryExtensionPath', this.telemetryExtensionDllPath);
259254
}
260255
}
261256

0 commit comments

Comments
 (0)