Skip to content

lsp-watch-root-folder follows symlinks that point outside the root folder #4973

@azuk

Description

@azuk

Thank you for the bug report

  • I am using the latest version of lsp-mode related packages.
  • I checked FAQ and Troubleshooting sections
  • You may also try reproduce the issue using clean environment using the following command: M-x lsp-start-plain

Bug description

I was wondering why visiting the first file in a Rust project froze Emacs for a minute or so on a very fast machine, consuming 100% of CPU all that time.

Turns out that lsp-watch-root-folder used for workspace/didChangeWatchedFiles walks the directory recursively using lsp--all-watchable-directories and it follows symlinks even when they point outside the root folder. In my case it ended up traversing the out-of-tree build directory which may contain over 200000 subdirectories IIRC and from there it even found its way to /var/log.

When debugging I also noticed that rust-analyzer provides glob patterns that limit what should actually be watched but lsp-mode seems to ignore them. In a large repository with lots of subprojects this may cause Emacs to watch a lot of unnecessary directories.

Steps to reproduce

  • Create for example a Rust project and inside it create a symlink to, say, /var
  • Add logging to lsp--all-watchable-directories or put a breakpoint to it using edebug or use some tracing feature.
  • Open a file inside the project so that rust-analyzer gets started for the project.
  • Observe the directories that lsp--all-watchable-directories traverses.

Expected behavior

  • lsp-watch-root-folder does not follow symlinks outside the root folder, at least not by default.
  • glob patterns provided by LSP server are used to limit what is watched

Which Language Server did you use?

rust-analyzer

OS

Linux

Error callstack

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions