diff --git a/src/node/entry.ts b/src/node/entry.ts index 90e5d91a..a030cb49 100644 --- a/src/node/entry.ts +++ b/src/node/entry.ts @@ -77,7 +77,11 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise httpServer.registerHttpProvider("/login", LoginHttpProvider, args.config!, envPassword) httpServer.registerHttpProvider("/static", StaticHttpProvider) - ipcMain().onDispose(() => httpServer.dispose()) + ipcMain().onDispose(() => { + httpServer.dispose().then((errors) => { + errors.forEach((error) => logger.error(error.message)) + }) + }) logger.info(`code-server ${version} ${commit}`) const serverAddress = await httpServer.listen() diff --git a/src/node/http.ts b/src/node/http.ts index 4628dd97..a4a83aea 100644 --- a/src/node/http.ts +++ b/src/node/http.ts @@ -177,7 +177,7 @@ export abstract class HttpProvider { public constructor(protected readonly options: HttpProviderOptions) {} - public dispose(): void { + public async dispose(): Promise { // No default behavior. } @@ -504,9 +504,15 @@ export class HttpServer { }) } - public dispose(): void { + /** + * Stop and dispose everything. Return an array of disposal errors. + */ + public async dispose(): Promise { this.socketProvider.stop() - this.providers.forEach((p) => p.dispose()) + const providers = Array.from(this.providers.values()) + // Catch so all the errors can be seen rather than just the first one. + const responses = await Promise.all(providers.map((p) => p.dispose().catch((e) => e))) + return responses.filter((r): r is Error => typeof r !== "undefined") } public async getConnections(): Promise {