private async cleanUp()

in src/debugger/cordovaDebugSession.ts [878:941]


    private async cleanUp(restart?: boolean): Promise<void> {
        const errorLogger = (message) => this.outputLogger(message, true);

        if (this.browserProc) {
            this.browserProc.kill("SIGINT");
            this.browserProc = null;
        }

        // Stop ADB port forwarding if necessary
        let adbPortPromise: Promise<void>;

        if (this.adbPortForwardingInfo) {
            const adbForwardStopArgs =
                ["-s", this.adbPortForwardingInfo.targetDevice,
                    "forward",
                    "--remove", `tcp:${this.adbPortForwardingInfo.port}`];
            adbPortPromise = this.runAdbCommand(adbForwardStopArgs, errorLogger)
                .then(() => void 0);
        } else {
            adbPortPromise = Promise.resolve();
        }

        // Kill the Ionic dev server if necessary
        let killServePromise: Promise<void>;

        if (this.ionicLivereloadProcess) {
            this.ionicLivereloadProcess.removeAllListeners("exit");
            killServePromise = killChildProcess(this.ionicLivereloadProcess).finally(() => {
                this.ionicLivereloadProcess = null;
            });
        } else {
            killServePromise = Promise.resolve();
        }

        // Clear the Ionic dev server URL if necessary
        if (this.ionicDevServerUrls) {
            this.ionicDevServerUrls = null;
        }

        // Close the simulate debug-host socket if necessary
        if (this.simulateDebugHost) {
            this.simulateDebugHost.close();
            this.simulateDebugHost = null;
        }

        if (this.cordovaCdpProxy) {
            await this.cordovaCdpProxy.stopServer();
            this.cordovaCdpProxy = null;
        }
        this.cancellationTokenSource.cancel();
        this.cancellationTokenSource.dispose();

        // Stop IWDP if necessary
        CordovaIosDeviceLauncher.cleanup();

        this.onDidTerminateDebugSessionHandler.dispose();
        this.sessionManager.terminate(this.cordovaSession.getSessionId(), !!restart);

        await logger.dispose();

        // Wait on all the cleanups
        return adbPortPromise
            .finally(() => killServePromise);
    }