microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.32k stars 28.59k forks source link

1.92 broke my exension "The task '<task name>' is already active" #225317

Open amylizzle opened 1 month ago

amylizzle commented 1 month ago

Does this issue occur when all extensions are disabled?: No

Steps to Reproduce:

  1. Install OpenDream extension https://github.com/OpenDreamProject/vscode-opendream
  2. Create a folder with an empty file called test.dme
  3. Launch

The OpenDream binaries are downloaded, and then this occurs: image

The extension seemed to be working fine (and does so on my laptop still) but other computers (also linux based) are encountering the same bug. It is unclear why.

vs-code-engineering[bot] commented 1 month ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.92.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

amylizzle commented 1 month ago

The task provider is providing this CustomExecution which is running, but the ProcessExecution doesn't run the executable and onDidEndTaskProcess() doesn't fire until you terminate the task.

getCompilerExecution(dme: string): vscode.CustomExecution {
        return new vscode.CustomExecution(
            async (resolvedDefinition): Promise<vscode.Pseudoterminal> => {
                await this.updateOpenDreamBinary(this.path);
                const writeEmitter = new vscode.EventEmitter<string>();
                const closeEmitter = new vscode.EventEmitter<number>();
                const pty: vscode.Pseudoterminal = {
                    onDidWrite: writeEmitter.event,
                    onDidClose: closeEmitter.event,
                    open: () => { },
                    close: () => { }
                };

                let PE = new ProcessExecution(`${this.path}/DMCompiler_${getArchSuffix()}/DMCompiler${os.platform() === "win32" ? ".exe" : ""}`, [
                    dme,
                ]);
                const task = new vscode.Task(
                    resolvedDefinition,
                    vscode.TaskScope.Workspace,
                    'compiler',
                    'custom',
                    PE
                );

                vscode.tasks.executeTask(task).then((t) => {
                    writeEmitter.fire('Process execution started.\r\n');
                    // Listen for task process end event
                    const disposable = vscode.tasks.onDidEndTaskProcess((event) => {
                        if (event.execution === t) {
                            if (event.exitCode === 0) {
                                writeEmitter.fire('Process execution completed successfully.\r\n');
                                closeEmitter.fire(0);
                            } else {
                                writeEmitter.fire(`Process execution failed with exit code ${event.exitCode}.\r\n`);
                                closeEmitter.fire(event.exitCode || 1);
                            }
                            disposable.dispose();
                        }
                    });
                }, (error) => {
                    writeEmitter.fire(`Process execution failed: ${error}\r\n`);
                    closeEmitter.fire(1);
                });
                return pty;
            });
    }
amylizzle commented 1 month ago

We found a workaround https://github.com/OpenDreamProject/vscode-opendream/pull/5

meganrogge commented 1 month ago

and you're sure this is new behavior as of 1.92? I'm not sure of any changes that could explain this

amylizzle commented 1 month ago

Oh sorry, no we tried rolling back and still encountered the issue. Honestly I'm not even sure how the extension ever worked in the first place. It seems like starting a Task from inside another Task just doesn't work randomly, it was very inconsistent.

meganrogge commented 1 month ago

Thanks for the info. Glad you found a workaround because honestly not sure when I will get to this, but your detailed report will help