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 #583

Closed
DetachHead opened this issue Dec 12, 2024 · 2 comments · Fixed by #585
Closed

memory leak #583

DetachHead opened this issue Dec 12, 2024 · 2 comments · Fixed by #585
Labels
bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities needs PR

Comments

@DetachHead
Copy link
Contributor

there seems to be a memory leak in the pylint extension's language server

Diagnostic Data

  • Python version (& distribution if applicable, e.g., Anaconda): 3.13
  • Type of virtual environment used (e.g., conda, venv, virtualenv, etc.): uv
  • Operating system (and version): windows 11
  • Version of tool extension you are using: 2024.0.0

Behaviour

Expected Behavior

extension does not take up 10gb of ram

Actual Behavior

lsp_server.py is using 10gb of ram

Image

Reproduction Steps:

i have no idea how to reproduce this reliably, but here's roughly what happened:

  1. left my PC on overnight
  2. log on in the morning and notice my C drive is out of space (could be unrelated, not sure)
  3. open task manager

Logs:

Click here for detailed logs
2024-12-11 17:01:29.576 [info] c:\Users\user\project\.venv\Scripts\python.exe -m pylint --reports=n --output-format=json --clear-cache-post-run=y --from-stdin c:\Users\user\project\foo.py
2024-12-11 17:01:29.578 [info] CWD Linter: c:\Users\user\project
2024-12-11 17:01:42.926 [info] file:///c%3A/Users/user/project/foo.py :
[]

2024-12-11 17:04:06.779 [info] c:\Users\user\project\.venv\Scripts\python.exe -m pylint --reports=n --output-format=json --clear-cache-post-run=y --from-stdin c:\Users\user\project\bar.py
2024-12-11 17:04:06.779 [info] CWD Linter: c:\Users\user\project
2024-12-11 18:48:29.059 [info] [Error - 6:48:29 PM] Traceback (most recent call last):
  File "c:\Users\user\.vscode\extensions\ms-python.pylint-2024.0.0\bundled\tool\lsp_server.py", line 787, in _run_tool_on_document
    result = utils.run_module(
        module=TOOL_MODULE,
    ...<3 lines>...
        source=document.source,
    )
  File "c:\Users\user\.vscode\extensions\ms-python.pylint-2024.0.0\bundled\tool\lsp_utils.py", line 208, in run_module
    return _run_module(module, argv, use_stdin, source)
  File "c:\Users\user\.vscode\extensions\ms-python.pylint-2024.0.0\bundled\tool\lsp_utils.py", line 199, in _run_module
    return RunResult(str_output.get_value(), str_error.get_value())
                                             ~~~~~~~~~~~~~~~~~~~^^
  File "c:\Users\user\.vscode\extensions\ms-python.pylint-2024.0.0\bundled\tool\lsp_utils.py", line 133, in get_value
    return self.read()
           ~~~~~~~~~^^
MemoryError

2024-12-11 18:48:29.063 [info] [Error - 6:48:29 PM] Linting failed with error:
Traceback (most recent call last):
  File "c:\Users\user\.vscode\extensions\ms-python.pylint-2024.0.0\bundled\tool\lsp_server.py", line 144, in _linting_helper
    result = _run_tool_on_document(document, use_stdin=True, extra_args=extra_args)
  File "c:\Users\user\.vscode\extensions\ms-python.pylint-2024.0.0\bundled\tool\lsp_server.py", line 787, in _run_tool_on_document
    result = utils.run_module(
        module=TOOL_MODULE,
    ...<3 lines>...
        source=document.source,
    )
  File "c:\Users\user\.vscode\extensions\ms-python.pylint-2024.0.0\bundled\tool\lsp_utils.py", line 208, in run_module
    return _run_module(module, argv, use_stdin, source)
  File "c:\Users\user\.vscode\extensions\ms-python.pylint-2024.0.0\bundled\tool\lsp_utils.py", line 199, in _run_module
    return RunResult(str_output.get_value(), str_error.get_value())
                                             ~~~~~~~~~~~~~~~~~~~^^
  File "c:\Users\user\.vscode\extensions\ms-python.pylint-2024.0.0\bundled\tool\lsp_utils.py", line 133, in get_value
    return self.read()
           ~~~~~~~~~^^
MemoryError

2024-12-11 18:48:29.147 [info] c:\Users\user\project\.venv\Scripts\python.exe -m pylint --reports=n --output-format=json --clear-cache-post-run=y --from-stdin c:\Users\user\project\bar.py
2024-12-11 18:48:29.147 [info] CWD Linter: c:\Users\user\project
2024-12-11 18:48:36.533 [info] Traceback (most recent call last):
  File "c:\Users\user\project\.venv\Lib\site-packages\pylint\lint\pylinter.py", line 977, in get_ast
    return astroid.builder.AstroidBuilder(MANAGER).string_build(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        data, modname, filepath
        ^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\builder.py", line 153, in string_build
    return self._post_build(module, builder, "utf-8")
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\builder.py", line 169, in _post_build
    self.delayed_assattr(delayed)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\builder.py", line 243, in delayed_assattr
    for inferred in node.expr.infer():
                    ~~~~~~~~~~~~~~~^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\nodes\node_ng.py", line 168, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
                     ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\decorators.py", line 86, in inner
    yield next(generator)
          ~~~~^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
               ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\nodes\node_classes.py", line 1760, in _infer
    for callee in self.func.infer(context):
                  ~~~~~~~~~~~~~~~^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\nodes\node_ng.py", line 168, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
                     ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\decorators.py", line 86, in inner
    yield next(generator)
          ~~~~^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
               ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\nodes\node_classes.py", line 1091, in _infer_attribute
    for owner in node.expr.infer(context):
                 ~~~~~~~~~~~~~~~^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\nodes\node_ng.py", line 168, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
                     ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\decorators.py", line 86, in inner
    yield next(generator)
          ~~~~^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
               ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\bases.py", line 177, in _infer_stmts
    for inf in stmt.infer(context=context):
               ~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\nodes\node_ng.py", line 168, in infer
    for i, result in enumerate(self._infer(context=context, **kwargs)):
                     ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\decorators.py", line 86, in inner
    yield next(generator)
          ~~~~^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\decorators.py", line 49, in wrapped
    for res in _func(node, context, **kwargs):
               ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\nodes\node_classes.py", line 2867, in _infer
    module = self.do_import_module()
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\nodes\_base_nodes.py", line 168, in do_import_module
    return mymodule.import_module(
           ~~~~~~~~~~~~~~~~~~~~~~^
        modname,
        ^^^^^^^^
    ...<2 lines>...
        use_cache=use_cache,
        ^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\nodes\scoped_nodes\scoped_nodes.py", line 462, in import_module
    return AstroidManager().ast_from_module_name(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        absmodname, use_cache=use_cache
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\manager.py", line 276, in ast_from_module_name
    return self.ast_from_file(found_spec.location, modname, fallback=False)
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\manager.py", line 166, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\builder.py", line 144, in file_build
    module, builder = self._data_build(data, modname, path)
                      ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\builder.py", line 181, in _data_build
    node, parser_module = _parse_string(
                          ~~~~~~~~~~~~~^
        data, type_comments=True, modname=modname
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\builder.py", line 477, in _parse_string
    parsed = parser_module.parse(
        data + "\n", type_comments=type_comments, filename=modname
    )
  File "c:\Users\user\project\.venv\Lib\site-packages\astroid\_ast.py", line 29, in parse
    return ast.parse(string, filename=filename, type_comments=type_comments)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Roaming\uv\python\cpython-3.13.0-windows-x86_64-none\Lib\ast.py", line 54, in parse
    return compile(source, filename, mode, flags,
                   _feature_version=feature_version, optimize=optimize)
MemoryError

@DetachHead
Copy link
Contributor Author

so i've narrowed this down to a pylint bug: pylint-dev/pylint#10137. this extension triggers this bug because it always seems to pass the file path in lowercase on windows:

pylint --reports=n --output-format=json --clear-cache-post-run=y --from-stdin c:\Users\user\project\tests\sandpit\__init__.py

when the file path is actually C:\Users\user\project\tests\sandpit\__init__.py (notice the different capitalization of the C:)

this is obviously a pylint issue and not this extension's fault, but i will leave this issue open as i think it's a severe enough issue that may warrant making a change to workaround it until the issue is resolved.

@karthiknadig karthiknadig added help wanted Issues identified as good community contribution opportunities needs PR and removed triage-needed Issue is not triaged. labels Dec 13, 2024
@karthiknadig
Copy link
Member

Thank you for looking into this and figuring out the root cause. I am open to taking a PR on this. These lines need to be updated:

if use_stdin:
argv += ["--from-stdin", document.path]
else:
argv += [document.path]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities needs PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants