From add82ea529f8dc63524db6c2bd84ed8f2eddc377 Mon Sep 17 00:00:00 2001 From: Ira Hopkinson Date: Wed, 14 Feb 2024 12:15:45 +1300 Subject: [PATCH] Improve extension host & dotnet service shutdown (#764) --- .../services/dotnet-data-provider.service.ts | 20 ++++++++++++++++--- src/main/services/extension-host.service.ts | 20 ++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/services/dotnet-data-provider.service.ts b/src/main/services/dotnet-data-provider.service.ts index 8e3582af5e..6de5c30cea 100644 --- a/src/main/services/dotnet-data-provider.service.ts +++ b/src/main/services/dotnet-data-provider.service.ts @@ -31,6 +31,8 @@ function killDotnetDataProvider() { } else { logger.error('dotnet data provider was not stopped! Investigate other .kill() options'); } + dotnet?.stderr?.removeListener('data', logProcessError); + dotnet?.stdout?.removeListener('data', logProcessInfo); dotnet = undefined; } @@ -69,7 +71,19 @@ function startDotnetDataProvider() { dotnet.stdout.on('data', logProcessInfo); dotnet.stderr.on('data', logProcessError); - dotnet.on('close', (code, signal) => { + dotnet.once('exit', (code, signal) => { + if (signal) { + logger.info(`'exit' event: dotnet data provider terminated with signal ${signal}`); + } else { + logger.info(`'exit' event: dotnet data provider exited with code ${code}`); + } + dotnet?.stderr?.removeListener('data', logProcessError); + dotnet?.stdout?.removeListener('data', logProcessInfo); + dotnet = undefined; + resolveClose(); + }); + + dotnet.once('close', (code, signal) => { // In production, this handles the closing of the data provider. However, in development, // this is handling the closing of the dotnet watcher. if (signal) { @@ -77,8 +91,8 @@ function startDotnetDataProvider() { } else { logger.info(`'close' event: dotnet data provider exited with code ${code}`); } - // TODO: listen for 'exit' event as well? - // TODO: unsubscribe event listeners + dotnet?.stderr?.removeListener('data', logProcessError); + dotnet?.stdout?.removeListener('data', logProcessInfo); dotnet = undefined; resolveClose(); }); diff --git a/src/main/services/extension-host.service.ts b/src/main/services/extension-host.service.ts index 5c6e0f257b..e89d94c915 100644 --- a/src/main/services/extension-host.service.ts +++ b/src/main/services/extension-host.service.ts @@ -53,6 +53,8 @@ function killExtensionHost() { } else { logger.error('extension host process was not stopped! Investigate other .kill() options'); } + extensionHost?.stderr?.removeListener('data', logProcessError); + extensionHost?.stdout?.removeListener('data', logProcessInfo); extensionHost = undefined; } @@ -129,14 +131,26 @@ async function startExtensionHost() { extensionHost.stdout.on('data', logProcessInfo); } - extensionHost.on('close', (code, signal) => { + extensionHost.once('exit', (code, signal) => { + if (signal) { + logger.info(`'exit' event: extension host process terminated with signal ${signal}`); + } else { + logger.info(`'exit' event: extension host process exited with code ${code}`); + } + extensionHost?.stderr?.removeListener('data', logProcessError); + extensionHost?.stdout?.removeListener('data', logProcessInfo); + extensionHost = undefined; + resolveClose(); + }); + + extensionHost.once('close', (code, signal) => { if (signal) { logger.info(`'close' event: extension host process terminated with signal ${signal}`); } else { logger.info(`'close' event: extension host process exited with code ${code}`); } - // TODO: listen for 'exit' event as well? - // TODO: unsubscribe event listeners + extensionHost?.stderr?.removeListener('data', logProcessError); + extensionHost?.stdout?.removeListener('data', logProcessInfo); extensionHost = undefined; resolveClose(); });