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

100% CPU and Memory usage since 0.18.2 #573

Closed
ElvenSpellmaker opened this issue Jul 1, 2021 · 13 comments · Fixed by #575
Closed

100% CPU and Memory usage since 0.18.2 #573

ElvenSpellmaker opened this issue Jul 1, 2021 · 13 comments · Fixed by #575
Labels
bug Something isn't working

Comments

@ElvenSpellmaker
Copy link

Server Version

0.18.2

Last Known Working version: 0.18.1

Terraform Version

0.13.1

Client Version

VSCode 1.57.1

Terraform Configuration Files

N/A I think

Log Output

Logging for starters throws an error using the default on the troubleshooting page Failed to setup logging for Terraform: template: tf-log-file:1: function "lsPid" not defined.

Either way I've tried to get the CPU and Memory logs and it never seems to generate any files (it was generating some 0 but CPU files but never populated them)

It generates the normal language server which ends with a lot of Receiving 1 notification:

2021/07/01 22:40:15 server.go:591: Received 1 new requests
2021/07/01 22:40:15 server.go:591: Received 1 new requests
2021/07/01 22:40:15 server.go:591: Received 1 new requests
2021/07/01 22:40:15 server.go:591: Received 1 new requests
2021/07/01 22:40:15 server.go:591: Received 1 new requests
2021/07/01 22:40:15 server.go:591: Received 1 new requests
2021/07/01 22:40:15 server.go:591: Received 1 new requests
2021/07/01 22:40:15 server.go:591: Received 1 new requests
2021/07/01 22:40:39 server.go:591: Received 1 new requests
2021/07/01 22:40:39 server.go:591: Received 1 new requests
2021/07/01 22:40:47 server.go:591: Received 1 new requests
2021/07/01 22:40:47 server.go:591: Received 1 new requests
2021/07/01 22:40:52 server.go:591: Received 1 new requests
2021/07/01 22:40:57 server.go:591: Received 1 new requests

And then stops.

Expected Behavior

VsCode to behave as usual

Actual Behavior

Memory and CPU spiral out of control almost making the system unusable. Killing the terraform-ls binary causes it to temporarily drop down.

Steps to Reproduce

code . with a project that contains terraform, within a few seconds of going to a tf file the CPU and memory will have spiralled out of control.

@lysacor
Copy link

lysacor commented Jul 1, 2021

I am seeing the same behavior

@KyleKotowick
Copy link

KyleKotowick commented Jul 2, 2021

Confirmed, it just crashed my comp with 64GB RAM when I tried to save 3 open files. This is a critical bug.

Is there a way to force the Hashicorp Terraform extension in VS Code to use an older version (0.18.1) instead?

EDIT: Answered my own question (on Windows at least).

  1. In VS Code, open the command palette (CTRL+SHIFT+P).
  2. Type Extensions: Open Extensions Folder.
  3. Open the hashicorp.terraform-* directory.
  4. Open the lsp directory.
  5. Replace the terraform-ls.exe file with the EXE from 0.18.1 (the .zip file from 0.18.1 may be in that same directory, as it was for me; in that case, just extract the EXE from it).
  6. Restart VS Code.
  7. VS Code will pop up a message asking if you want to install 0.18.2. I suggest that you do not do that.

@radeksimko
Copy link
Member

Hi folks,
Sorry for any inconvenience.

Can any of you share any more details? Namely:

  • configuration that triggers this, and/or
  • beginning of the log (from Launching language server:), or ideally just whole log

Screenshot 2021-07-02 at 09 10 18

I was not able to reproduce this unfortunately.

@radeksimko radeksimko added the bug Something isn't working label Jul 2, 2021
@ElvenSpellmaker
Copy link
Author

Hey @radeksimko The most useful logs, Memory, CPU, and TF Logs don't generate at all. The main log doesn't have any errors in it, it just seems to opening files by scanning the whole repo.

If there's any way I can get more detailed logs then I could try, I tried turning on trace.server option in vscode but to no avail.

It just seems to load some modules in the repo up and then spirals out of control.

@radeksimko
Copy link
Member

The main log doesn't have any errors in it, it just seems to opening files by scanning the whole repo.

I don't expect it to have errors, based on the snippet above but it would help to know what happens after the launch and which requests are and are not processed. Do you mind sharing the relevant part of the log?

Memory, CPU, and TF Logs don't generate at all

Both CPU & memory profiles are written into after the shutdown of the process - which should happen automatically if you shut down VS Code. It is also worth mentioning that if you have multiple folders in your workspace then each folder would be served by a different LS process and so the flags should use the templating (such as {{pid}}) to allow collecting profiles per process and avoid processes writing into the same file over each other.

https://github.com/hashicorp/terraform-ls/blob/main/docs/TROUBLESHOOTING.md#cpu-profiling
https://github.com/hashicorp/terraform-ls/blob/main/docs/TROUBLESHOOTING.md#memory-profiling

Thanks.

@ElvenSpellmaker
Copy link
Author

I tried to get the logs to generate but vscode doesn't generate them using 0.18.2 even after shutdown of vscode.

@radeksimko
Copy link
Member

@ElvenSpellmaker Do you mind sharing the configuration, so I can try reproducing it myself?

You may also encrypt it and/or send it privately to radek<at>hashicorp.com if you prefer.

@ElvenSpellmaker
Copy link
Author

@radeksimko I'll send the logs for 0.18.1 and 0.18.2 to your e-mail, they're not super private, but it'd be easier that way. 🙂

@radeksimko
Copy link
Member

radeksimko commented Jul 2, 2021

@ElvenSpellmaker was kind enough to provide a working repro case privately.

I am still investigating the root cause, but I have some confidence to say that this is being triggered by some nested objects, such as

locals {
  top_obj = {
    first = {
      attr = "val"
    }
    second = {
      attr = "val"
    }
    third = {
      attr = "val"
    }
    fourth = {
      attr = "val"
    }
  }
}

^ that is the most minimal snippet I was able to extract and still reproduce the bug

Thank you for your patience.

@radeksimko
Copy link
Member

Thank you @ElvenSpellmaker for the report and for helping to reproduce this.

It is fixed in 0.18.3 which was just released.

VS Code should prompt you to upgrade upon next launch or in the next 24 hours.

@ElvenSpellmaker
Copy link
Author

@radeksimko Excellent, thanks Radek!

@ElvenSpellmaker
Copy link
Author

I can confirm the newer version seems to have patched the issue.

@github-actions
Copy link

github-actions bot commented Aug 2, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants