terraform-ls: Very High CPU consumption

Server Version

0.4.1

Terraform Version

0.12.24

Client Version

neovim (v0.4.3) coc plugin

Terraform Configuration Files

Log Output

https://gist.github.com/jamesskinner/b759199add68935349926b9e052d9bbd

Expected Behaviour

minimal cpu usage

Actual Behaviour

99.9% cpu usage

Steps to Reproduce

I donโ€™t see a specific scenario. I do work on a codebase containing multiple root terraform repositories in subfolders. I am on MacOS v10.15.4

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (12 by maintainers)

Most upvoted comments

Thank you all (and @jamesskinner in particular) for your help in debugging. #236 with the patch was just merged and released as part of 0.5.2.

I managed to come up with a reliable repro case which leads to pretty much the same hot path highlighted in my collected CPU profile as @jamesskinner 's (and indeed 100% CPU usage)

provider "null" {
}

variable "name" {
  default = "
}

^ triggered by completion near the unclosed double quote (default = "<HERE>)

Iโ€™m going to try to isolate the code which is causing this.

@m1keil and anyone else coming here to report high CPU related issues - please check that you are on the latest language server version - v0.5.1 (the VS Code extension updates it automatically when VS Code launches).

If the problem persists then I would greatly appreciate if you can modify the launch arguments in Settings to collect the CPU profile and attach that profile to your comment here for further inspection.

Thank you ๐Ÿ™

Added the log into my previous comment. If I just open a file, CPU does not spike, in fact what I did with this process is open neovim and open a buffer from all the terraform root subdirectories in my repository (10 or 11), then I just left it and for a say or so nothing happened. Then today I actually started to write some code and the CPU started spiking. Every time this happens it goes up to 100% and stays there no matter if I am using the editor or not

@radeksimko. Yep I was running 5.0.0 ๐Ÿ˜ƒ I updated to latest, the process was running for a day or so before I actually started to use it, at which point I saw the same issue.

Here are memory and cpu profile files:

terraform-ls-prof.zip terraform-ls-87908-log.zip

~I have not included the log file, but can if needed~ included the log file

I have just shipped 0.5.0 which is now also installable via Homebrew btw.

Do you mind updating and try to collect the CPU profile via the new flag as documented here? https://github.com/hashicorp/terraform-ls/blob/master/docs/TROUBLESHOOTING.md#cpu-profiling

I removed the extra log output as it was just logging lsp request and responses and contains code (which does not belong to me). There is no continuous logging output going on while the editor is idle and the terraform-ls process is still consuming all the CPU.

If I get some time today I will try and do the profiling and encrypt some log output

Another note on my setup that might be relevant - I usually have multiple editor sessions open so there are often multiple terraform-ls processes running at the same time. Anecdotally I think only the process related to the more complicated codebase I described above causes issues, the others work as expected and consume expected amounts of CPU