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

Plugin crashed with invalid memory address or nil pointer dereference #1055

Open
sonalm opened this issue May 21, 2024 · 13 comments
Open

Plugin crashed with invalid memory address or nil pointer dereference #1055

sonalm opened this issue May 21, 2024 · 13 comments

Comments

@sonalm
Copy link

sonalm commented May 21, 2024

Plugin crashes with following error:

The plugin encountered an error, and failed to respond to the
plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more
details.

Stack trace from the terraform-provider-azuredevops_v0.2.0 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xf3de25]

goroutine 28 [running]:
github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/serviceendpoint.doBaseFlattening(0xc00067d030, 0xc000292ab0, 0xc000354c10)
	github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/serviceendpoint/commons.go:119 +0x1e5
github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/serviceendpoint.flattenServiceEndpointAzureRM(0xc00067d030, 0xc000292ab0, 0xc000354c10)
	github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/serviceendpoint/resource_serviceendpoint_azurerm.go:112 +0x4c
github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/serviceendpoint.genServiceEndpointReadFunc.func1(0xc00067d030, 0xff7e20, 0xc00008ea00, 0xc00067d030, 0x0)
	github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/serviceendpoint/commons.go:222 +0x374
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc000220500, 0xc0003159a0, 0xff7e20, 0xc00008ea00, 0xc000308390, 0x0, 0x0)
	github.com/hashicorp/terraform-plugin-sdk@v1.17.2/helper/schema/resource.go:470 +0x12e
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadResource(0xc0001391d0, 0x13f7d50, 0xc0007bd4a0, 0xc00064c720, 0xc0001391d0, 0xc0007bd4a0, 0xc000287ba0)
	github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/helper/plugin/grpc_provider.go:535 +0x3dd
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadResource_Handler(0x11ac360, 0xc0001391d0, 0x13f7d50, 0xc0007bd4a0, 0xc00064c6c0, 0x0, 0x13f7d50, 0xc0007bd4a0, 0xc000050a80, 0x33c)
	github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/tfplugin5/tfplugin5.pb.go:3269 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00022efc0, 0x1405f78, 0xc000001800, 0xc00008e600, 0xc0005abb30, 0x19f54b0, 0x0, 0x0, 0x0)
	google.golang.org/grpc@v1.32.0/server.go:1194 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc00022efc0, 0x1405f78, 0xc000001800, 0xc00008e600, 0x0)
	google.golang.org/grpc@v1.32.0/server.go:1517 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc0000342c0, 0xc00022efc0, 0x1405f78, 0xc000001800, 0xc00008e600)
	google.golang.org/grpc@v1.32.0/server.go:859 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
	google.golang.org/grpc@v1.32.0/server.go:857 +0x1fd

Error: The terraform-provider-azuredevops_v0.2.0 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Can you please highlight what could be the reason behind this error?

@sonalm
Copy link
Author

sonalm commented May 22, 2024

Even after upgrading the plugin version, i still get the following error:

The plugin.(*GRPCProvider).ReadResource request was cancelled.

Stack trace from the terraform-provider-azuredevops_v1.1.1 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xcc0f0e]

goroutine 70 [running]:
github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/serviceendpoint.resourceServiceEndpointAzureRMRead(0x0?, {0xd85520?, 0xc0000c6600})
	github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/serviceendpoint/resource_serviceendpoint_azurerm.go:229 +0x10e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x10c8ca0?, {0x10c8ca0?, 0xc00029e3f0?}, 0xd?, {0xd85520?, 0xc0000c6600?})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/resource.go:712 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc00045a540, {0x10c8ca0, 0xc00029e3f0}, 0xc0000da750, {0xd85520, 0xc0000c6600})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/resource.go:1015 +0x585
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc0003174b8, {0x10c8ca0?, 0xc00029e210?}, 0xc0000e1680)
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/grpc_provider.go:613 +0x497
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc0003f2be0, {0x10c8ca0?, 0xc00027f5c0?}, 0xc0002a27e0)
	github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/tf5server/server.go:748 +0x49e
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0xf0bae0?, 0xc0003f2be0}, {0x10c8ca0, 0xc00027f5c0}, 0xc00042ebd0, 0x0)
	github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:349 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000436000, {0x10cba40, 0xc000092820}, 0xc0005f65a0, 0xc000495020, 0x166b610, 0x0)
	google.golang.org/grpc@v1.56.3/server.go:1335 +0xde3
google.golang.org/grpc.(*Server).handleStream(0xc000436000, {0x10cba40, 0xc000092820}, 0xc0005f65a0, 0x0)
	google.golang.org/grpc@v1.56.3/server.go:1712 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.1()
	google.golang.org/grpc@v1.56.3/server.go:947 +0xca
created by google.golang.org/grpc.(*Server).serveStreams.func1
	google.golang.org/grpc@v1.56.3/server.go:958 +0x15c

Error: The terraform-provider-azuredevops_v1.1.1 plugin crashed!

i believe from looking at the code that it is mostly referring to ServiceEndpointProjectReferences being null.

So, i want to understand, when would that be the case? where/how does it get its value from?

@xuzhang3
Copy link
Collaborator

@sonalm this might be the permission issue that not all the SE properties are returned by service. The flatten operation try to get the properties but get nil exception

@clumsyhands
Copy link

I am having the same issue.

I have created the service connection manually with "Azure Resource Manager using Workload Identity federation with OpenID Connect (automatic)", this service connection is part of the "Project Collection Administrators" Azure DevOps group, and I have enabled it to use OIDC:

provider "azuredevops" {
  org_service_url     = "https://dev.azure.com/xxx/"
  use_oidc        = true
}

What exactly is the issue here?

@xuzhang3 xuzhang3 added this to the v0.10.0 milestone May 27, 2024
@xuzhang3
Copy link
Collaborator

@clumsyhands @sonalm can you share your TF script?

@hugolm20
Copy link

I am having the same issue.

The TF script is

terraform {
  required_providers {
    azuredevops = {
      source  = "microsoft/azuredevops"
      version = ">=0.1.0"
    }
  }
}

provider "azuredevops" {
  org_service_url       = var.org_service_url
  personal_access_token = var.personal_access_token
}

data "azuredevops_project" "project" {
  name = var.project_name
}

resource "azuredevops_serviceendpoint_sonarqube" "example" {
  project_id            = var.project_id
  service_endpoint_name = "Sonarqube Connection"
  url                   = var.sonarqube_url
  token                 = var.sonarqube_token
  description           = "Managed by Terraform"
}

The message error that I received is:

Error: The terraform-provider-azuredevops_v1.1.1 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Am I doing something wrong?

@VazquezAgustin
Copy link

Facing the same issue!

@rahuja23
Copy link

rahuja23 commented Jun 4, 2024

Facing the same issue. Any idea why this is happening?

@hugolm20
Copy link

hugolm20 commented Jun 4, 2024

I think it is a problem of go code.
"panic: runtime error: invalid memory address or nil pointer dereference"

@NikolaiKleppe
Copy link

NikolaiKleppe commented Jun 6, 2024

Facing similar issues.

For me it started happening after I manually deleted a repository that was managed by Terraform, I guess that was a bad idea on my part. Then nothing worked at all even after commenting out all the code.

However in my case I managed to solve it by removing that specific repository from state, then it worked again.
terraform state remove <resource>

So I suppose this error could happen if someone made a change (or deleted) a resource that is managed by Terraform. For your case it might be a serviceconnection/serviceendpoint:

github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/serviceendpoint.doBaseFlattening(0xc00067d030, 0xc000292ab0, 0xc000354c10)

For me it was repos:
github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/git.flattenGitRepository(0x12648cd0, 0x0)

@b-rand
Copy link

b-rand commented Jun 11, 2024

Facing similar issues.

For me it started happening after I manually deleted a repository that was managed by Terraform, I guess that was a bad idea on my part. Then nothing worked at all even after commenting out all the code.

However in my case I managed to solve it by removing that specific repository from state, then it worked again. terraform state remove <resource>

So I suppose this error could happen if someone made a change (or deleted) a resource that is managed by Terraform. For your case it might be a serviceconnection/serviceendpoint:

github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/serviceendpoint.doBaseFlattening(0xc00067d030, 0xc000292ab0, 0xc000354c10)

For me it was repos: github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/git.flattenGitRepository(0x12648cd0, 0x0)

Can confirm, I deleted a test repository that I created via the provider and observed the same issue.

@NikolaiKleppe
Copy link

NikolaiKleppe commented Jun 21, 2024

Occured again for us, with the following culprit:

I set up the initial Terraform configuration locally on my Windows machine, using PAT authentication to deploy. This is working as expected currently.

When I run our CI/CD pipeline using Linux agent with a federated credentials service connection (with the exact same Terraform Version and providers) it crashes on Terraform Plan:

Stack trace from the terraform-provider-azuredevops_v1.1.1 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xcc0f0e]

goroutine 152 [running]:
github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/serviceendpoint.resourceServiceEndpointAzureRMRead(0x0?, {0xd85520?, 0xc000368c00})
	github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/service/serviceendpoint/resource_serviceendpoint_azurerm.go:229 +0x10e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x10c8ca0?, {0x10c8ca0?, 0xc00037d290?}, 0xd?, {0xd85520?, 0xc000368c00?})

Seems to me there are issues using federated credentials with the DevOps provider, as others have mentioned using it as well

@hugolm20
Copy link

@NikolaiKleppe
About your first comment: it’s make sense. I faced the error after deleted a service connection managed terraform of azure devops.
I’ll try to create the same in other repo.

about the second: you faced a simillar error, right? Just the message “invalid memory…” is the same. Is the reason different?

@NikolaiKleppe
Copy link

@hugolm20
The error message is different compared to when i deleted a resource. Now in the second example it's the same as @sonalm's original error (after updating to 1.1.1) and seems to be related to Federated Identity service connection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants