Skip to content

Commit af26148

Browse files
committed
watcher - enable crash reports on linux (#136264)
1 parent fd3b9ad commit af26148

File tree

5 files changed

+59
-11
lines changed

5 files changed

+59
-11
lines changed

src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class SharedProcessMain extends Disposable {
195195
services.set(ILogService, logService);
196196

197197
// Worker
198-
this.sharedProcessWorkerService = new SharedProcessWorkerService(logService);
198+
this.sharedProcessWorkerService = new SharedProcessWorkerService(logService, productService, environmentService);
199199
services.set(ISharedProcessWorkerService, this.sharedProcessWorkerService);
200200

201201
// Files

src/vs/platform/sharedProcess/electron-browser/sharedProcessWorker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export interface ISharedProcessWorkerEnvironment {
2929
* Full absolute path to our `bootstrap-fork.js` file.
3030
*/
3131
bootstrapPath: string;
32+
33+
/**
34+
* Extra environment to use for the process to fork.
35+
*/
36+
env: NodeJS.ProcessEnv;
3237
}
3338

3439
interface IBaseMessage {

src/vs/platform/sharedProcess/electron-browser/sharedProcessWorkerMain.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class SharedProcessWorkerProcess extends Disposable {
124124
}
125125

126126
spawn(): void {
127-
Logger.trace('Forking worker process');
127+
Logger.trace(`Forking worker process (env: ${JSON.stringify(this.environment.env)})`);
128128

129129
// Fork module via bootstrap-fork for AMD support
130130
this.child = fork(
@@ -194,6 +194,7 @@ class SharedProcessWorkerProcess extends Disposable {
194194
private getEnv(): NodeJS.ProcessEnv {
195195
const env: NodeJS.ProcessEnv = {
196196
...deepClone(process.env),
197+
...this.environment.env,
197198
VSCODE_AMD_ENTRYPOINT: this.configuration.process.moduleId,
198199
VSCODE_PIPE_LOGGING: 'true',
199200
VSCODE_VERBOSE_LOGGING: 'true',

src/vs/platform/sharedProcess/electron-browser/sharedProcessWorkerService.ts

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

6-
import { ipcRenderer } from 'electron';
6+
import { CrashReporterStartOptions, ipcRenderer } from 'electron';
7+
import { join } from 'path';
78
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
89
import { Emitter } from 'vs/base/common/event';
910
import { Disposable } from 'vs/base/common/lifecycle';
1011
import { FileAccess } from 'vs/base/common/network';
11-
import { generateUuid } from 'vs/base/common/uuid';
12+
import { isLinux } from 'vs/base/common/platform';
13+
import { generateUuid, isUUID } from 'vs/base/common/uuid';
14+
import { INativeEnvironmentService } from 'vs/platform/environment/common/environment';
1215
import { ILogService } from 'vs/platform/log/common/log';
16+
import { IProductService } from 'vs/platform/product/common/productService';
1317
import { hash, IOnDidTerminateSharedProcessWorkerProcess, ISharedProcessWorkerConfiguration, ISharedProcessWorkerProcessExit, ISharedProcessWorkerService } from 'vs/platform/sharedProcess/common/sharedProcessWorkerService';
14-
import { SharedProcessWorkerMessages, ISharedProcessToWorkerMessage, IWorkerToSharedProcessMessage } from 'vs/platform/sharedProcess/electron-browser/sharedProcessWorker';
18+
import { SharedProcessWorkerMessages, ISharedProcessToWorkerMessage, IWorkerToSharedProcessMessage, ISharedProcessWorkerEnvironment } from 'vs/platform/sharedProcess/electron-browser/sharedProcessWorker';
1519

1620
export class SharedProcessWorkerService implements ISharedProcessWorkerService {
1721

@@ -23,7 +27,9 @@ export class SharedProcessWorkerService implements ISharedProcessWorkerService {
2327
private readonly processResolvers = new Map<number /* process configuration hash */, (process: IOnDidTerminateSharedProcessWorkerProcess) => void>();
2428

2529
constructor(
26-
@ILogService private readonly logService: ILogService
30+
@ILogService private readonly logService: ILogService,
31+
@IProductService private readonly productService: IProductService,
32+
@INativeEnvironmentService private readonly environmentService: INativeEnvironmentService
2733
) {
2834
}
2935

@@ -117,7 +123,7 @@ export class SharedProcessWorkerService implements ISharedProcessWorkerService {
117123
if (!webWorkerPromise) {
118124
this.logService.trace(`SharedProcess: creating new web worker (${configuration.process.moduleId})`);
119125

120-
const sharedProcessWorker = new SharedProcessWebWorker(configuration.process.type, this.logService);
126+
const sharedProcessWorker = new SharedProcessWebWorker(configuration.process.type, this.logService, this.productService, this.environmentService);
121127
webWorkerPromise = sharedProcessWorker.init();
122128

123129
// Make sure to run through our normal `disposeWorker` call
@@ -156,7 +162,9 @@ class SharedProcessWebWorker extends Disposable {
156162

157163
constructor(
158164
private readonly type: string,
159-
private readonly logService: ILogService
165+
private readonly logService: ILogService,
166+
private readonly productService: IProductService,
167+
private readonly environmentService: INativeEnvironmentService
160168
) {
161169
super();
162170
}
@@ -280,14 +288,47 @@ class SharedProcessWebWorker extends Disposable {
280288
const workerMessage: ISharedProcessToWorkerMessage = {
281289
id: SharedProcessWorkerMessages.Spawn,
282290
configuration,
283-
environment: {
284-
bootstrapPath: FileAccess.asFileUri('bootstrap-fork', require).fsPath
285-
}
291+
environment: this.getSharedProcessWorkerEnvironment()
286292
};
287293

288294
return this.send(workerMessage, token, port);
289295
}
290296

297+
private getSharedProcessWorkerEnvironment(): ISharedProcessWorkerEnvironment {
298+
const sharedProcessWorkerEnvironment = {
299+
bootstrapPath: FileAccess.asFileUri('bootstrap-fork', require).fsPath,
300+
env: Object.create(null)
301+
};
302+
303+
// Crash reporter support
304+
// TODO@bpasero TODO@deepak1556 remove once we updated to Electron 15
305+
if (isLinux) {
306+
const crashReporterStartOptions: CrashReporterStartOptions = {
307+
companyName: this.productService.crashReporter?.companyName || 'Microsoft',
308+
productName: this.productService.crashReporter?.productName || this.productService.nameShort,
309+
submitURL: '',
310+
uploadToServer: false
311+
};
312+
313+
const crashReporterId = this.environmentService.args['crash-reporter-id']; // crashReporterId is set by the main process only when crash reporting is enabled by the user.
314+
const appcenter = this.productService.appCenter;
315+
const uploadCrashesToServer = !this.environmentService.args['crash-reporter-directory']; // only upload unless --crash-reporter-directory is provided
316+
if (uploadCrashesToServer && appcenter && crashReporterId && isUUID(crashReporterId)) {
317+
const submitURL = appcenter[`linux-x64`];
318+
crashReporterStartOptions.submitURL = submitURL.concat('&uid=', crashReporterId, '&iid=', crashReporterId, '&sid=', crashReporterId);
319+
crashReporterStartOptions.uploadToServer = true;
320+
}
321+
// In the upload to server case, there is a bug in electron that creates client_id file in the current
322+
// working directory. Setting the env BREAKPAD_DUMP_LOCATION will force electron to create the file in that location,
323+
// For https://github.com/microsoft/vscode/issues/105743
324+
const extHostCrashDirectory = this.environmentService.args['crash-reporter-directory'] || this.environmentService.userDataPath;
325+
sharedProcessWorkerEnvironment.env.BREAKPAD_DUMP_LOCATION = join(extHostCrashDirectory, `Parcel Watcher Crash Reports`);
326+
sharedProcessWorkerEnvironment.env.VSCODE_CRASH_REPORTER_START_OPTIONS = JSON.stringify(crashReporterStartOptions);
327+
}
328+
329+
return sharedProcessWorkerEnvironment;
330+
}
331+
291332
terminate(configuration: ISharedProcessWorkerConfiguration, token: CancellationToken): Promise<void> {
292333
const workerMessage: ISharedProcessToWorkerMessage = {
293334
id: SharedProcessWorkerMessages.Terminate,

src/vs/workbench/services/extensions/electron-browser/localProcessExtensionHost.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ export class LocalProcessExtensionHost implements IExtensionHost {
277277
}
278278

279279
// On linux crash reporter needs to be started on child node processes explicitly
280+
// TODO@bpasero TODO@deepak1556 remove once we updated to Electron 15
280281
if (platform.isLinux) {
281282
const crashReporterStartOptions: CrashReporterStartOptions = {
282283
companyName: this._productService.crashReporter?.companyName || 'Microsoft',

0 commit comments

Comments
 (0)