Skip to content

workspaceStorage storage leak #134532

@hinell

Description

@hinell
// file: $HOME/.config/Code/User/workspaceStorage/xxxxxxxxxxxxxxhash/workspace.json
{
  "folder": "file:///path/to/projects/2021/foo/project-name-fork"
}

The above is the only way that VS Code currently associates workspace cache with a specific project residing in the folder: .....

Once the project's folder path gets renamed VS Code loses its reference to the project cache. Upon launching the cache gets rebuilt from scratch once again (ignoring the previous one). If repeated for several times the cache will grow enormously, wasting the startup-time and HDD storage space. C/C++ projects will turn into a storage killer (see related issues below).

Discovery

I got a C++ project that got indexed (including dependencies) multiple times. Later I've moved it into another place so it got indexed once again. The same thing happened to a whole range of other C++ projects and forks I have. I ended up with having a significant amount of gigabytes wasted. 😑

Steps to Reproduce:

Assuming you are using Linux-based OS and zsh/bash.

  1. Install C/C++ tools extension
  2. Get any C/C++ project: e.g.
    $ git clone --depth 1 --no-tags https://github.com/madler/zlib /tmp/zlib-0
  3. Remember the number of dirs in .../workspaceStorage, like so:
    $ dir -d $HOME/.config/Code/User/workspaceStorage/* | wc -l
  4. Open in VS Code, wait until cache gets indexed, close VS Code, rename the folder, open it up once again
    $ code /tmp/zlib-0
    $ mv /tmp/zlib-0 /tmp/zlib-1
    $ code /tmp/zlib-1
  5. Repeat the last 2 steps and see the number of folders in .../workspaceStorage growing

Solutions proposal

  1. Make it configurable so one can keep cache in the .vscode folder
  2. Somehow mark the workspace (e.g. by a cookie) and keep its value both inside workspace.json and .vscode, making the cache a workspace-path-independent
  3. Regularly clean stale caches - should be very cheap to implement and maintain

Workaround

As a temporarily solution I've made a simple bash script to audit cache files, checkout: code.workspaces.cache.filter


Versions

  • VS Code Version: 1.60.2 and earlier
  • OS Version: Kubuntu 20.04 - Kubuntu 21.04 / x64

Extensions

  • C/C++ tools [v1.6.0] - Not a culprit in this case for sure

Related issues

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions