microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.54k stars 1.56k forks source link

Compile commands file watchers are leaked without being closed #12946

Closed yiftahw closed 2 weeks ago

yiftahw commented 2 weeks ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary:

When using compileCommands in a configuration, deleting the json file causes the fallback function checkCompileCommands() in src\LanguageServer\configurations.ts to dispose the file watchers without closing them.

Steps to reproduce:

  1. Use the compileCommands configuration with a path to a compile_commands.json.
  2. Update the file's timestamp. (touch it or compile a CMake project which updates it)
    • CppProperties.compileCommandsFile is updated with a value.
  3. Delete or rename the file.
  4. next periodic call to checkCompileCommands() will enter the error case and leak the file watchers.
    // in checkCompileCommands()
    fs.stat(compileCommandsFile, (err, stats) => {
    if (err) {
        if (err.code === "ENOENT" && this.compileCommandsFile) {
            // file watchers should be closed here
            this.compileCommandsFileWatchers = []; // reset file watchers

Expected behavior: checkCompileCommands() should close the file watchers before disposing.

Configuration and Logs

{
    "configurations": [
        {
            "name": "compdb1",
            "compileCommands": "${workspaceFolder}/compile_commands_1.json",
            "intelliSenseMode": "windows-msvc-x64",
            "cStandard": "c17",
            "cppStandard": "c++17"
        },
        {
            "name": "compdb2",
            "compileCommands": "${workspaceFolder}/compile_commands_2.json",
            "intelliSenseMode": "linux-gcc-x64",
            "cStandard": "c17",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}

Other Extensions

No response

Additional context

No response