Skip to content

Commit

Permalink
[ipc] use args instead of env variables for debugging
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosiakov <[email protected]>
  • Loading branch information
akosyakov committed Dec 4, 2017
1 parent cd3a613 commit c7eea4e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,14 @@ export class ApplicationPackageManager {
THEIA_PARENT_PID: String(process.pid)
}
};
const debug = Number(process.env['THEIA_DEBUG']);
if (typeof debug === 'number' && !isNaN(debug)) {
options.execArgv = ['--nolazy', '--inspect=' + debug];
}
const debugBrk = Number(process.env['THEIA_DEBUG_BRK']);
if (typeof debugBrk === 'number' && !isNaN(debugBrk)) {
options.execArgv = ['--nolazy', '--inspect-brk=' + debugBrk];
const mainArgs = [...args];
const inspectIndex = mainArgs.findIndex(v => v.startsWith('--inspect'));
if (inspectIndex !== -1) {
const inspectArg = mainArgs.splice(inspectIndex, 1)[0];
options.execArgv = ['--nolazy', inspectArg];
}
return this.__process.bunyan(
this.__process.fork(this.pck.backend('main.js'), args, options)
this.__process.fork(this.pck.backend('main.js'), mainArgs, options)
);
}

Expand Down
17 changes: 6 additions & 11 deletions packages/core/src/node/messaging/ipc-connection-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export interface ResolvedIPCConnectionOptions {
readonly entryPoint: string
readonly logger: ILogger
readonly args: string[]
readonly debug?: number
readonly debugBrk?: number
readonly errorHandler?: ConnectionErrorHandler
}
export type IPCConnectionOptions = Partial<ResolvedIPCConnectionOptions> & {
Expand Down Expand Up @@ -84,18 +82,15 @@ export class IPCConnectionProvider {
protected fork(options: ResolvedIPCConnectionOptions): cp.ChildProcess {
const forkOptions: cp.ForkOptions = {
silent: true,
env: createIpcEnv({
env: process.env,
entryPoint: options.entryPoint
}),
env: createIpcEnv(options),
execArgv: []
};
if (typeof options.debug === 'number' && !isNaN(options.debug)) {
forkOptions.execArgv = ['--nolazy', '--inspect=' + options.debug];
}
if (typeof options.debugBrk === 'number' && !isNaN(options.debugBrk)) {
forkOptions.execArgv = ['--nolazy', '--inspect-brk=' + options.debugBrk];
const inspectArgPrefix = `--${options.serverName}-inspect`;
const inspectArg = process.argv.find(v => v.startsWith(inspectArgPrefix));
if (inspectArg !== undefined) {
forkOptions.execArgv = ['--nolazy', `--inspect${inspectArg.substr(inspectArgPrefix.length)}`];
}

const childProcess = cp.fork(path.resolve(__dirname, 'ipc-bootstrap.js'), options.args, forkOptions);
childProcess.stdout.on('data', data => this.logger.info(`[${options.serverName}: ${childProcess.pid}] ${data.toString()}`));
childProcess.stderr.on('data', data => this.logger.error(`[${options.serverName}: ${childProcess.pid}] ${data.toString()}`));
Expand Down
2 changes: 0 additions & 2 deletions packages/filesystem/src/node/filesystem-watcher-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ export class FileSystemWatcherServerClient implements FileSystemWatcherServer {
return this.ipcConnectionProvider.listen({
serverName: NSFW_WATCHER,
entryPoint: path.resolve(__dirname, NSFW_WATCHER),
debug: Number(process.env['FS_WATCH_DEBUG']),
debugBrk: Number(process.env['FS_WATCH_DEBUG_BRK']),
errorHandler: new ConnectionErrorHandler({
serverName: NSFW_WATCHER,
logger: this.logger
Expand Down
4 changes: 1 addition & 3 deletions packages/git/src/node/git-locator/git-locator-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ export class GitLocatorClient implements GitLocator {
return new Promise((resolve, reject) => {
const toStop = this.ipcConnectionProvider.listen({
serverName: 'git-locator',
entryPoint: paths.resolve(__dirname, 'git-locator-host'),
debug: Number(process.env['GIT_LOCATE_DEBUG']),
debugBrk: Number(process.env['GIT_LOCATE_DEBUG_BRK'])
entryPoint: paths.resolve(__dirname, 'git-locator-host')
}, async connection => {
const proxyFactory = new JsonRpcProxyFactory<GitLocator>();
const remote = proxyFactory.createProxy();
Expand Down

0 comments on commit c7eea4e

Please sign in to comment.