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

Fix panic on obtaining provider schemas #1048

Merged
merged 2 commits into from
Aug 24, 2022
Merged

Fix panic on obtaining provider schemas #1048

merged 2 commits into from
Aug 24, 2022

Conversation

dbanck
Copy link
Member

@dbanck dbanck commented Aug 24, 2022

This PR fixes the LS panic reported in hashicorp/vscode-terraform#1213.

Stack trace:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x13c4898]

goroutine 38 [running]:
github.com/hashicorp/go-version.prereleaseCheck(0xc09a8067e0, 0x3)
github.com/hashicorp/go-version@v1.6.0/constraint.go:198 +0x18
github.com/hashicorp/go-version.constraintGreaterThanEqual(0xc09a8067e8, 0xc0aa07f858)
github.com/hashicorp/go-version@v1.6.0/constraint.go:250 +0x25
github.com/hashicorp/go-version.(*Constraint).Check(...)
github.com/hashicorp/go-version@v1.6.0/constraint.go:163
github.com/hashicorp/go-version.Constraints.Check({0xc0cb192370, 0x1, 0xc}, 0x170c841)
github.com/hashicorp/go-version@v1.6.0/constraint.go:93 +0x5e
github.com/hashicorp/terraform-ls/internal/state.(*ProviderSchemaStore).schemaExists(0xc0007ed6c0, {{0xc0c90cacfa, 0x6}, {0xc0c90cacf0, 0x9}, {0x1714198, 0x15}}, {0xc0cb192370, 0x1, 0x1})
github.com/hashicorp/terraform-ls/internal/state/provider_schema.go:227 +0x9c9
github.com/hashicorp/terraform-ls/internal/state.(*ProviderSchemaStore).AllSchemasExist(0xc0008924c0, 0xc0604fc2a7)
github.com/hashicorp/terraform-ls/internal/state/provider_schema.go:197 +0xef
github.com/hashicorp/terraform-ls/internal/terraform/module.ObtainSchema({0x1d64de0, 0xc053b1f980}, 0x163d6a0, 0xc0bbe71c60, {0xc0604fc2a7, 0x64})
github.com/hashicorp/terraform-ls/internal/terraform/module/module_ops.go:128 +0xea
github.com/hashicorp/terraform-ls/internal/indexer.(*Indexer).WalkedModule.func8({0x1d64de0, 0xc053b1f950})
github.com/hashicorp/terraform-ls/internal/indexer/walker.go:135 +0xc5
github.com/hashicorp/terraform-ls/internal/scheduler.(*Scheduler).eval(0xc00088d5c0, {0x1d64d38, 0xc000892500})
github.com/hashicorp/terraform-ls/internal/scheduler/scheduler.go:70 +0x184
created by github.com/hashicorp/terraform-ls/internal/scheduler.(*Scheduler).Start
github.com/hashicorp/terraform-ls/internal/scheduler/scheduler.go:48 +0x69

Background

We have two jobs, one to obtain the provider schema via terraform providers schema -json and one to get the Terraform and provider versions via terraform version -json. We track provider schemas in a memdb table, and both jobs add their results to a schema entry in this table. Only the results of both jobs combined produce a usable schema.

Since we delayed the execution of Terraform version in terraform-ls #1014, we can end up with a schema without a version in the table. The check whether a schema version matches the constrains panics in certain conditions. It panics for constraints like >= 1.0.0, but not 1.0.0.

The introduction of dependsOn for jobs should avoid getting into a situation like this in the first place. The job for obtaining the schema, depends on the job for parsing the provider versions:

pSchemaId, err := idx.jobStore.EnqueueJob(job.Job{
Dir: modHandle,
Func: func(ctx context.Context) error {
ctx = exec.WithExecutorFactory(ctx, idx.tfExecFactory)
return module.ObtainSchema(ctx, idx.modStore, idx.schemaStore, modHandle.Path())
},
Type: op.OpTypeObtainSchema.String(),
DependsOn: dependsOn,
})

This is now possible since we delay the execution of obtaining
the Terraform version.
@dbanck dbanck added the bug Something isn't working label Aug 24, 2022
@dbanck dbanck marked this pull request as ready for review August 24, 2022 13:32
@dbanck dbanck requested a review from a team as a code owner August 24, 2022 13:32
@dbanck dbanck self-assigned this Aug 24, 2022
@dbanck dbanck merged commit 8bd42b4 into main Aug 24, 2022
@dbanck dbanck deleted the b-fix-schema-panic branch August 24, 2022 13:55
@dbanck dbanck added this to the v0.29.1 milestone Aug 24, 2022
@bigbitbus
Copy link

I am facing this issue; how can I use the fix you just merged?

@github-actions
Copy link

This functionality has been released in v0.29.1 of the language server.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@dbanck
Copy link
Member Author

dbanck commented Aug 24, 2022

Hi @bigbitbus! This fix has been released in the latest version of the language server. So you can either download the language server binary and update your extension settings to use it. Or wait for the v2.24.1 release of the extension we're in the process of releasing. VS Code should automatically update for the latter.

@github-actions
Copy link

I'm going to lock this pull request 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 related to this change, 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 Sep 24, 2022
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 this pull request may close these issues.

None yet

3 participants