From ffe64dab3cbc3aa99faa6390f6d894fa065eed58 Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Tue, 20 Jun 2023 14:30:07 -0700 Subject: [PATCH] cli: fix error starting remote tunnels (#185701) * untested wip * cli: fix error starting remote tunnels Fixes #185585 Output was prefixed which prevented the lines from being split to detect the tunnel status. --- build/gulpfile.vscode.win32.js | 1 + build/win32/code.iss | 28 +++++++++++++++++-- .../remoteTunnel/node/remoteTunnelService.ts | 8 +++--- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/build/gulpfile.vscode.win32.js b/build/gulpfile.vscode.win32.js index 6e9a6f331ba..7886037d2ba 100644 --- a/build/gulpfile.vscode.win32.js +++ b/build/gulpfile.vscode.win32.js @@ -101,6 +101,7 @@ function buildWin32Setup(arch, target) { AppMutex: product.win32MutexName, TunnelMutex: product.win32TunnelMutex, TunnelServiceMutex: product.win32TunnelServiceMutex, + TunnelApplicationName: product.tunnelApplicationName, ApplicationName: product.applicationName, Arch: arch, AppId: { 'ia32': ia32AppId, 'x64': x64AppId, 'arm64': arm64AppId }[arch], diff --git a/build/win32/code.iss b/build/win32/code.iss index 7754562225b..f584830e618 100644 --- a/build/win32/code.iss +++ b/build/win32/code.iss @@ -1362,7 +1362,7 @@ begin end; end; - if IsNotBackgroundUpdate() and CheckForMutexes('{#TunnelMutex}') then + if IsNotBackgroundUpdate() and not StopTunnelProcesses() then begin MsgBox('{#NameShort} is still running a tunnel. Please stop the tunnel before installing.', mbInformation, MB_OK); Result := false @@ -1380,6 +1380,30 @@ end; var ShouldRestartTunnelService: Boolean; +function StopTunnelProcesses(); +var + WaitCounter: Integer; + TaskKilled: Integer; +begin + Log('Stopping all tunnel services with taskkill'); + Exec('taskkill.exe', '/f /im "' + ExpandConstant('"{app}\bin\{#TunnelApplicationName}.exe"') + '"', '', SW_HIDE, ewWaitUntilTerminated, TaskKilled); + + WaitCounter := 10; + while (WaitCounter > 0) and CheckForMutexes('{#TunnelMutex}') do + begin + Log('Tunnel process is is still running, waiting'); + Sleep(500); + WaitCounter := WaitCounter - 1 + end; + + if CheckForMutexes('{#TunnelMutex}') then + Log('Unable to stop tunnel processes') + exit(False) + else + exit(True) + end +end; + procedure StopTunnelServiceIfNeeded(); var StopServiceResultCode: Integer; @@ -1607,4 +1631,4 @@ begin #endif Exec(ExpandConstant('{sys}\icacls.exe'), ExpandConstant('"{app}" /inheritancelevel:r ') + Permissions, '', SW_HIDE, ewWaitUntilTerminated, ResultCode); -end; \ No newline at end of file +end; diff --git a/src/vs/platform/remoteTunnel/node/remoteTunnelService.ts b/src/vs/platform/remoteTunnel/node/remoteTunnelService.ts index e3cee9778a2..84ccef33653 100644 --- a/src/vs/platform/remoteTunnel/node/remoteTunnelService.ts +++ b/src/vs/platform/remoteTunnel/node/remoteTunnelService.ts @@ -340,13 +340,13 @@ export class RemoteTunnelService extends Disposable implements IRemoteTunnelServ } }); if (!this.environmentService.isBuilt) { - onOutput('Building tunnel CLI from sources and run', false); - onOutput(`${logLabel} Spawning: cargo run -- tunnel ${commandArgs.join(' ')}`, false); + onOutput('Building tunnel CLI from sources and run\n', false); + onOutput(`${logLabel} Spawning: cargo run -- tunnel ${commandArgs.join(' ')}\n`, false); tunnelProcess = spawn('cargo', ['run', '--', 'tunnel', ...commandArgs], { cwd: join(this.environmentService.appRoot, 'cli'), stdio }); } else { - onOutput('Running tunnel CLI', false); + onOutput('Running tunnel CLI\n', false); const tunnelCommand = this.getTunnelCommandLocation(); - onOutput(`${logLabel} Spawning: ${tunnelCommand} tunnel ${commandArgs.join(' ')}`, false); + onOutput(`${logLabel} Spawning: ${tunnelCommand} tunnel ${commandArgs.join(' ')}\n`, false); tunnelProcess = spawn(tunnelCommand, ['tunnel', ...commandArgs], { cwd: homedir(), stdio }); }