eclipse-theia / theia

Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
http://theia-ide.org
Eclipse Public License 2.0
20.05k stars 2.5k forks source link

Memoryleak in plugin-host with setInterval #13407

Open BrightKn1ght opened 8 months ago

BrightKn1ght commented 8 months ago

Bug Description:

I have written my own plugin which is periodically making a get request. With theia 1.46.1 and the browser-example, I see the memory of process plugin-host is growing very rapidly. In 10min up to 700MB.

When installing the exact same plugin in theia 1.34.4 the memory stays constant. I commented all out in my plugin to exclude any side effects. This is the minimal code required to reproduce the issue:

import vscode = require('vscode');
import got = require('got');

export const logDebug = vscode.window.createOutputChannel("debugging");

export function activate(context: vscode.ExtensionContext) {

    const gotOptions = () => {
        let options = {
            baseUrl: `https://doesnotmatter}`,
            headers: {
                'Authorization': `Bearer asdf`,
                'Host': 'localhost'
            },
            rejectUnauthorized: false
        }
        return options;
    }

    const statusBarItem = vscode.window.createStatusBarItem();
    const toggleStatus = async () => {
        try {
            logDebug.appendLine("polling...")
            const data = await got.get('/someurl', { ...gotOptions(), json: true })
            if ('value' in data.body) {
                return data.body.value;
            } else {
                return data.body;
            }
            // normally i do here some usefull things with data.

        } catch (error) {
            statusBarItem.text = `$(tools) Please configure plugin`
        }

        statusBarItem.show();
    }
    setInterval(toggleStatus, 5000)
}

I also replaced the got library with the axios library to see if the error comes from there. But it had no effect.

Steps to Reproduce:

  1. Create a plugin with the above code and watch the memory of process plugin-host increasing.
  2. I attached the plugin and the sources of it.

Additional Information

JonasHelming commented 8 months ago

Hi, thank you for the report. Would it be possible to attach the plugin you have to reproduce this?

BrightKn1ght commented 8 months ago

Hi Jonas, sure. leaky-plugin.zip The zip contains my sources and the visx file.