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

Memory Leak when using MessageService#showProgress on Backend #13253

Closed
jfaltermeier opened this issue Jan 10, 2024 · 0 comments · Fixed by #13254
Closed

Memory Leak when using MessageService#showProgress on Backend #13253

jfaltermeier opened this issue Jan 10, 2024 · 0 comments · Fixed by #13254
Assignees
Milestone

Comments

@jfaltermeier
Copy link
Contributor

Bug Description:

There is a memory leak when using e.g. MessageService#showProgress on the backend when the Progress is updated many times.

In RpcProtocol new event listeners are added via cancellationToken?.onCancellationRequested(() => this.sendCancel(id)) on each update, but those are not removed again.

This will result in these kind of warnings on the backend log:

2024-01-10T11:24:18.341Z root WARN Possible Emitter memory leak detected. 176 listeners added. Use event.maxListeners to increase the limit (175). MOST frequent listener (1):
2024-01-10T11:24:18.341Z root WARN     at _event.Object.assign.maxListeners (/home/user/git/theia/examples/electron/lib/backend/packages_core_lib_common_index_js-node_modules_vscode-languageserver-types_lib_umd_sync_recursive.js:1430:54)
    at RpcProtocol.sendRequest (/home/user/git/theia/examples/electron/lib/backend/packages_core_lib_common_index_js-node_modules_vscode-languageserver-types_lib_umd_sync_recursive.js:3546:101)
    at /home/user/git/theia/examples/electron/lib/backend/packages_core_lib_common_index_js-node_modules_vscode-languageserver-types_lib_umd_sync_recursive.js:4236:58
    at new Promise (<anonymous>)
    at /home/user/git/theia/examples/electron/lib/backend/packages_core_lib_common_index_js-node_modules_vscode-languageserver-types_lib_umd_sync_recursive.js:4229:64

Steps to Reproduce:

  1. Execute this code on the backend:
    @inject(MessageService)
    protected readonly messages: MessageService;

    async init(): Promise<void> {
        const progress = await this.messages.showProgress({ text: 'Progressing...', options: { cancelable: false } });
        for (let i = 1; i <= 1000; i++) {
            progress.report({ message: undefined, work: { done: i, total: 1000 } });
            await wait(50); // import { wait } from '@theia/core/lib/common/promise-util';
        }
    }

(e.g. temporarily add it to packages/git/src/node/init/git-init.ts at the start of the init() method, which already uses the MessageService)

  1. Let this run for some time and check that there are multiple logs about the leak.

Additional Information

  • Operating System: Ubuntu 22.04
  • Theia Version: 1.45.0
@jfaltermeier jfaltermeier self-assigned this Jan 10, 2024
jfaltermeier added a commit that referenced this issue Jan 10, 2024
* dispose cancellation event listeners in RpcProtocol
jfaltermeier added a commit that referenced this issue Jan 10, 2024
* dispose cancellation event listeners in RpcProtocol
jfaltermeier added a commit that referenced this issue Jan 10, 2024
* dispose cancellation event listeners in RpcProtocol
jfaltermeier added a commit that referenced this issue Jan 10, 2024
* dispose cancellation event listeners in RpcProtocol
jfaltermeier added a commit that referenced this issue Jan 15, 2024
* renamed MaybeDisposable to DisposableWrapper
jfaltermeier added a commit that referenced this issue Jan 15, 2024
…13254)

* dispose cancellation event listeners in RpcProtocol
* introduce common DisposableWrapper
@jfaltermeier jfaltermeier added this to the 1.46.0 milestone Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant