From 6b5f50cddfc66f580e3547433114bb24606a58e4 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 19 Feb 2019 17:53:14 -0600 Subject: [PATCH] Handle shared process `error` event; add some logging --- packages/server/src/vscode/sharedProcess.ts | 39 ++++++++++++++------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/packages/server/src/vscode/sharedProcess.ts b/packages/server/src/vscode/sharedProcess.ts index 675cdc489..ce0bedb67 100644 --- a/packages/server/src/vscode/sharedProcess.ts +++ b/packages/server/src/vscode/sharedProcess.ts @@ -7,7 +7,7 @@ import { StdioIpcHandler } from "../ipc"; import { ParsedArgs } from "vs/platform/environment/common/environment"; import { Emitter } from "@coder/events/src"; import { retry } from "@coder/ide/src/retry"; -import { logger, Level } from "@coder/logger"; +import { logger, field, Level } from "@coder/logger"; export enum SharedProcessState { Stopped, @@ -30,6 +30,7 @@ export class SharedProcess { private readonly onStateEmitter = new Emitter(); public readonly onState = this.onStateEmitter.event; private readonly retryName = "Shared process"; + private readonly logger = logger.named("shared"); public constructor( private readonly userDataDir: string, @@ -65,12 +66,34 @@ export class SharedProcess { state: SharedProcessState.Starting, }); let resolved: boolean = false; + const maybeStop = (error: string): void => { + if (resolved) { + return; + } + this.setState({ + error, + state: SharedProcessState.Stopped, + }); + if (!this.activeProcess) { + return; + } + this.activeProcess.kill(); + }; this.activeProcess = forkModule("vs/code/electron-browser/sharedProcess/sharedProcessMain", [], { env: { VSCODE_ALLOW_IO: "true", VSCODE_LOGS: process.env.VSCODE_LOGS, }, }); + if (this.logger.level <= Level.Trace) { + this.activeProcess.stdout.on("data", (data) => { + this.logger.trace(() => ["stdout", field("data", data.toString())]); + }); + } + this.activeProcess.on("error", (error) => { + this.logger.error("error", field("error", error)); + maybeStop(error.message); + }); this.activeProcess.on("exit", (err) => { if (this._state !== SharedProcessState.Stopped) { this.setState({ @@ -92,7 +115,7 @@ export class SharedProcess { "user-data-dir": this.userDataDir, "extensions-dir": extensionsDir, }, - logLevel: logger.level, + logLevel: this.logger.level, sharedIPCHandle: this.socketPath, }; this.ipcHandler!.send("handshake:hey there", "", data); @@ -105,16 +128,8 @@ export class SharedProcess { }); }); this.activeProcess.stderr.on("data", (data) => { - if (!resolved) { - this.setState({ - error: data.toString(), - state: SharedProcessState.Stopped, - }); - if (!this.activeProcess) { - return; - } - this.activeProcess.kill(); - } + this.logger.error("stderr", field("data", data.toString())); + maybeStop(data.toString()); }); }