Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task terminals with a failed process task aren't always reused properly #141939

Merged
merged 3 commits into from Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts
Expand Up @@ -840,7 +840,8 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
});
});
promise = new Promise<ITaskSummary>((resolve, reject) => {
const onExit = terminal!.onExit((exitCode) => {
const onExit = terminal!.onExit((terminalLaunchResult) => {
const exitCode = typeof terminalLaunchResult === 'number' ? terminalLaunchResult : terminalLaunchResult?.code;
onData.dispose();
onExit.dispose();
let key = task.getMapKey();
Expand All @@ -849,7 +850,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
}
this.removeFromActiveTasks(task);
this.fireTaskEvent(TaskEvent.create(TaskEventKind.Changed));
if (exitCode !== undefined) {
if (terminalLaunchResult !== undefined) {
// Only keep a reference to the terminal if it is not being disposed.
switch (task.command.presentation!.panel) {
case PanelKind.Dedicated:
Expand Down Expand Up @@ -878,15 +879,15 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
processStartedSignaled = true;
}

this.fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessEnded, task, exitCode));
this.fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessEnded, task, exitCode ?? undefined));

for (let i = 0; i < eventCounter; i++) {
this.fireTaskEvent(TaskEvent.create(TaskEventKind.Inactive, task));
}
eventCounter = 0;
this.fireTaskEvent(TaskEvent.create(TaskEventKind.End, task));
toDispose.dispose();
resolve({ exitCode });
resolve({ exitCode: exitCode ?? undefined });
});
});
} else {
Expand Down Expand Up @@ -919,12 +920,13 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
startStopProblemMatcher.processLine(line);
});
promise = new Promise<ITaskSummary>((resolve, reject) => {
const onExit = terminal!.onExit((exitCode) => {
const onExit = terminal!.onExit((terminalLaunchResult) => {
const exitCode = typeof terminalLaunchResult === 'number' ? terminalLaunchResult : terminalLaunchResult?.code;
onExit.dispose();
let key = task.getMapKey();
this.removeFromActiveTasks(task);
this.fireTaskEvent(TaskEvent.create(TaskEventKind.Changed));
if (exitCode !== undefined) {
if (terminalLaunchResult !== undefined) {
// Only keep a reference to the terminal if it is not being disposed.
switch (task.command.presentation!.panel) {
case PanelKind.Dedicated:
Expand Down Expand Up @@ -961,13 +963,13 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
processStartedSignaled = true;
}

this.fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessEnded, task, exitCode));
this.fireTaskEvent(TaskEvent.create(TaskEventKind.ProcessEnded, task, exitCode ?? undefined));
if (this.busyTasks[mapKey]) {
delete this.busyTasks[mapKey];
}
this.fireTaskEvent(TaskEvent.create(TaskEventKind.Inactive, task));
this.fireTaskEvent(TaskEvent.create(TaskEventKind.End, task));
resolve({ exitCode });
resolve({ exitCode: exitCode ?? undefined });
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Expand Up @@ -522,10 +522,10 @@ export interface ITerminalInstance {

/**
* Attach a listener that fires when the terminal's pty process exits. The number in the event
* is the processes' exit code, an exit code of null means the process was killed as a result of
* is the processes' exit code, an exit code of undefined means the process was killed as a result of
* the ITerminalInstance being disposed.
*/
onExit: Event<number | undefined>;
onExit: Event<number | ITerminalLaunchError | undefined>;

readonly exitCode: number | undefined;

Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Expand Up @@ -287,7 +287,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {

// The onExit event is special in that it fires and is disposed after the terminal instance
// itself is disposed
private readonly _onExit = new Emitter<number | undefined>();
private readonly _onExit = new Emitter<number | ITerminalLaunchError | undefined>();
readonly onExit = this._onExit.event;
private readonly _onDisposed = this._register(new Emitter<ITerminalInstance>());
readonly onDisposed = this._onDisposed.event;
Expand Down Expand Up @@ -1412,7 +1412,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
}

// First onExit to consumers, this can happen after the terminal has already been disposed.
this._onExit.fire(this._exitCode);
this._onExit.fire(exitCodeOrError);

// Dispose of the onExit event if the terminal will not be reused again
if (this._isDisposed) {
Expand Down