Infinite loop sending output to an output channel from an extension makes VS Code stop responding

Previous statement was wrong: Constantly sending output to an output channel (as in an infinite loop printing data) from an extension makes VS Code stop responding. This happened both with the stable and alpha release.
@alexandrudima I would believe this is a general issue and not so much about output. Any extension can trigger API in an endless loop and that will likely spam the renderer enough to make it unresponsive. Do we do some throttling with regards to data traveling from a spammy extension back to the main side?
If an extension enters an infinite loop, AFAIK we have no graceful way to terminate it besides killing the extension host process.
I will investigate if buffering the output service is something that helps here but it would not help in all cases of abuse.
@digeff I am not able to reproduce with a simple example, is it possible to share the extension with me to reproduce?
@bpasero Sorry for the delay, I meant something like this (This makes my VS Code unresponsive consistently):
export function activate(context: vscode.ExtensionContext) {
let disposable = vscode.commands.registerCommand('extension.sayHello', () => {
vscode.window.showInformationMessage('Crashing!');
lotsOfOutput();
});
context.subscriptions.push(disposable);
}
function lotsOfOutput() {
setTimeout(() => {
const outputChannel = vscode.window.createOutputChannel("Test");
outputChannel.show();
outputChannel.appendLine("Stop working please...");
lotsOfOutput();
lotsOfOutput();
}, 100);
}
@isidorn can you try this out? asking because you recently pushed a change to handle output updates with a 300ms delay directly in the UI layer and maybe we are good to go already.
So the example that the user provided still can crash vscode because it is a quadratic function which creates new output, shows the output channel and appends the output. However the following can no longer crash / slow down vscode
const outputChannel = vscode.window.createOutputChannel("Test");
setInterval(() => {
outputChannel.appendLine("Stop working please...");
}, 10);
Sorry, have to reopen, would like to understand why we still crash and if we can prevent that.
@isidorn What if you set the interval time to 0?
Ok, the cause of the crash was the multiple calls to show(), now I protect against that. Please note that the original sample provided by @digeff still crashes after some time since it converges to infinity.
@digeff regarding interval 0 https://stackoverflow.com/questions/7648557/setinterval-behaviour-with-0-milliseconds-in-javascript
@isidorn What if we use process.nextTick instead of interval 0? (Basically, I want to simulate adding output as fast as possible, while not yet converging to infinity).
@digeff if I setInterval for 1ms it does not crash any more with the latest fixes
:heart: