Skip to content

Commit 1b5e250

Browse files
committed
Don't restart pty host when shutting down
1 parent 78cdc57 commit 1b5e250

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

src/vs/platform/terminal/electron-main/electronPtyHostStarter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ export class ElectronPtyHostStarter implements IPtyHostStarter {
2323

2424
private readonly _onBeforeWindowConnection = new Emitter<void>();
2525
readonly onBeforeWindowConnection = this._onBeforeWindowConnection.event;
26+
private readonly _onWillShutdown = new Emitter<void>();
27+
readonly onWillShutdown = this._onWillShutdown.event;
2628

2729
constructor(
2830
private readonly _reconnectConstants: IReconnectConstants,
2931
@IEnvironmentService private readonly _environmentService: INativeEnvironmentService,
3032
@ILifecycleMainService private readonly _lifecycleMainService: ILifecycleMainService,
3133
@ILogService private readonly _logService: ILogService
3234
) {
35+
this._lifecycleMainService.onWillShutdown(() => this._onWillShutdown.fire());
3336
// Listen for new windows to establish connection directly to pty host
3437
validatedIpcMain.on('vscode:createPtyHostMessageChannel', (e, nonce) => this._onWindowConnection(e, nonce));
3538
}

src/vs/platform/terminal/node/ptyHost.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface IPtyHostConnection {
1515

1616
export interface IPtyHostStarter {
1717
onBeforeWindowConnection?: Event<void>;
18+
onWillShutdown?: Event<void>;
1819

1920
/**
2021
* Creates a pty host and connects to it.

src/vs/platform/terminal/node/ptyHostService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export class PtyHostService extends Disposable implements IPtyService {
5757

5858
private readonly _shellEnv: Promise<typeof process.env>;
5959
private readonly _resolveVariablesRequestStore: RequestStore<string[], { workspaceId: string; originalText: string[] }>;
60+
private _wasQuitRequested = false;
6061
private _restartCount = 0;
6162
private _isResponsive = true;
6263
private _isDisposed = false;
@@ -105,6 +106,7 @@ export class PtyHostService extends Disposable implements IPtyService {
105106

106107
this._register(toDisposable(() => this._disposePtyHost()));
107108

109+
108110
this._resolveVariablesRequestStore = this._register(new RequestStore(undefined, this._logService));
109111
this._resolveVariablesRequestStore.onCreateRequest(this._onPtyHostRequestResolveVariables.fire, this._onPtyHostRequestResolveVariables);
110112

@@ -115,6 +117,8 @@ export class PtyHostService extends Disposable implements IPtyService {
115117
} else {
116118
this._ensurePtyHost();
117119
}
120+
121+
this._ptyHostStarter.onWillShutdown?.(() => this._wasQuitRequested = true);
118122
}
119123

120124
private get _ignoreProcessNames(): string[] {
@@ -140,7 +144,6 @@ export class PtyHostService extends Disposable implements IPtyService {
140144
}
141145

142146
private _startPtyHost(): [IPtyHostConnection, IPtyService] {
143-
this._logService.info('startPtyHost', new Error().stack);
144147
const connection = this._ptyHostStarter.start(lastPtyId);
145148
const client = connection.client;
146149

@@ -154,7 +157,7 @@ export class PtyHostService extends Disposable implements IPtyService {
154157
// Handle exit
155158
this._register(connection.onDidProcessExit(e => {
156159
this._onPtyHostExit.fire(e.code);
157-
if (!this._isDisposed) {
160+
if (!this._wasQuitRequested && !this._isDisposed) {
158161
if (this._restartCount <= Constants.MaxRestarts) {
159162
this._logService.error(`ptyHost terminated unexpectedly with code ${e.code}`);
160163
this._restartCount++;

src/vs/workbench/contrib/terminal/browser/baseTerminalBackend.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export abstract class BaseTerminalBackend extends Disposable {
4444
let unresponsiveNotification: INotificationHandle | undefined;
4545
if (eventSource.onPtyHostStart) {
4646
this._register(eventSource.onPtyHostStart(() => {
47-
this._logService.info(`ptyHost restarted`);
4847
this._onPtyHostRestart.fire();
4948
unresponsiveNotification?.close();
5049
unresponsiveNotification = undefined;

0 commit comments

Comments
 (0)