terraform-ls: OpTypeGetModuleDataFromRegistry Client.Timeout exceeded while awaiting headers

Server Version

0.29.1
platform: darwin/amd64
go: go1.17.13
compiler: gc

Terraform Version

Terraform v1.2.8
on darwin_amd64

Client Version

VSCode Hashicorp Terraform v2.24.1

Log Output

2022/08/26 13:24:26 jobs.go:90: JOBS: Enqueueing new job "9963": "OpTypeGetModuleDataFromRegistry" for {"file:///Users/user/tf-test"} (IsDirOpen: true, IgnoreState: false)
2022/08/26 13:24:26 jobs.go:265: JOBS: Dispatching next job "9963" (scheduler prio: -1, job prio: -1, isDirOpen: true): "OpTypeGetModuleDataFromRegistry" for {"file:///Users/user/tf-test"}
2022/08/26 13:24:31 jobs.go:380: JOBS: Finishing job "9963": "OpTypeGetModuleDataFromRegistry" for {"file:///Users/user/tf-test"} (err = 1 error occurred:
	* Get "https://registry.terraform.io/v1/modules/terraform-google-modules/iam/google/versions": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

, deferredJobs: [])

Expected Behavior

VSCode should format terraform file on save and do it instantly

Actual Behavior

After I’ve upgraded my Mac to macOS Monterey a week ago I started noticing that VSCode is really slow on save when working with terraform code. I have found a couple of threads discussing the issues with tfenv which I don’t use. What I did:

  • updated brew to the latest version
  • uninstalled all previously installed terraform versions via brew
  • added hashicorp/tap to brew
  • installed latest versions of terraform and terraform-ls via brew hashicorp/tap
  • upgraded/uninstalled/reinstalled terraform plugin for VSCode
  • updated Terraform plugin configuration pointing to the binaries directly (/usr/local/bin/terraform and /usr/local/bin/terraform-ls)

Nothing from the above solved the issue I started looking at the output of the plugin and saw this timeout error while getting module versions I can open this url in my browser successfully and instantly so it’s not the network issue (I guess?)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 28 (12 by maintainers)

Most upvoted comments

I guess there’s another question remaining - why this golang snippet worked fine when talking to registry.terraform.io? #1050 (comment)

Maybe timeout is too small in the terraform-ls?

That is an interesting question to solve but out of scope for us. Both are using the same (5s) timeout.

I’m closing this issue in favor of #1063, which condenses all information about the slow/blocked RPC requests.

Thank you again for the fantastic collaboration!

Exciting find and fix via the /etc/hosts file. Thanks for confirming that everything works now. Make sure to remember to update the entry the next time fastly decides to update their DNS record 😉

We introduced completion, hover, and docs links for uninitialized registry modules in https://github.com/hashicorp/terraform-ls/pull/924. This change was part of the 0.29.0 release. Before that release, we didn’t make any HTTP requests to the Terraform registry. So that’s why 0.28.0 was working for you.

The remaining unsolved part is why hanging HTTP requests block the language server when a file is formatted. A missing, slow, or unstable network connection shouldn’t affect the formatting of files. But that’s for us to solve.

Thanks for being so responsive and trying all our suggestions ❤️

I’m slowly running out of ideas, but one other thing we could do is obtain more debug logs. Can you run the LS in TCP mode with GODEBUG=http2debug=2 set and paste the logs? That would tell us where exactly it hangs.

GODEBUG=http2debug=2 terraform-ls serve -port 3333

This is the start of the main.tf file:

/********************************
 Data ETL Process Components
********************************/

data "google_project" "project" {
  project_id = var.project_id
}

Coming back to the failed registry HTTP calls. Are you behind some proxy? You have “http.proxySupport”: “off” in your VS Code config?

No, I don’t use a proxy, this was just a sanity check when I saw timeout but it didn’t help

Does saving feels slow? Like a 5 seconds delay?

This is NOT the original code I posted the logs from - I created a test folder to be able to share it

When I hit Cmd+S there’s a progress bar at the bottom of the VSCode that can go away in 5-10 seconds, or stay there until I hit cancel. In this particular case formatting did eventually happened and file was saved, but it took around 30 seconds it feels like. This is the updated gist log with the save showed in the screenshot https://gist.github.com/tpolekhin/899f6e8078b84e8b43807709bb75b999

Screenshot 2022-08-26 at 15 14 22

I made a new terraform folder with just google-iam module inside This is the output.log gist from the start of the vscode till file was saved and output flow stopped https://gist.github.com/tpolekhin/d6b5e42e0ba64bb747cc10d5c29f1472