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

Failed GRPCProvider requests and Xray provider crash #144

Closed
aserzhankou opened this issue Oct 31, 2023 · 2 comments
Closed

Failed GRPCProvider requests and Xray provider crash #144

aserzhankou opened this issue Oct 31, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@aserzhankou
Copy link

Describe the bug
Hello. Raising a separate issue, as it was suggested in the comments #141 (comment)

I have problems with Xray provider upgrade from version to 1.12 to any version from 1.15 to 2.0.0.

In the plan I have a lot of UpgradeResourceState errors like this:

│ Error: Request cancelled
│ 
│   with module.remote-maven-spring-plugins.xray_repository_config.remote-maven-xray-config,
│   on .terraform/modules/remote-maven-spring-plugins/ops/terraform/modules/remote-maven-repo/main.tf line 48, in resource "xray_repository_config" "remote-maven-xray-config":
│   48: resource "xray_repository_config" "remote-maven-xray-config" {
│ 
│ The plugin.(*GRPCProvider).UpgradeResourceState request was cancelled.

And as a result:

Stack trace from the terraform-provider-xray_v2.0.0 plugin:

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

goroutine 81 [running]:
github.com/jfrog/terraform-provider-xray/pkg/xray.resourceXrayRepositoryConfig.func7(0x0, {0xc000138778, 0x4})
        github.com/jfrog/terraform-provider-xray/pkg/xray/resource_xray_repository_config.go:354 +0x10b
github.com/jfrog/terraform-provider-xray/pkg/xray.resourceXrayRepositoryConfig.func8(0xc0007864e0, {0xc000451c70, 0x6}, {0xc000138778, 0x4})
        github.com/jfrog/terraform-provider-xray/pkg/xray/resource_xray_repository_config.go:381 +0x2b8
github.com/jfrog/terraform-provider-xray/pkg/xray.resourceXrayRepositoryConfig.func12({0x1c?, 0xcaae12?}, {{0xc0007b3660?, 0x203000?}, 0xc0007864e0?, 0x0?}, 0xc0003900c0?, {0xc000451c70, 0x6}, {0xc000138778, ...})
        github.com/jfrog/terraform-provider-xray/pkg/xray/resource_xray_repository_config.go:430 +0x117
github.com/jfrog/terraform-provider-xray/pkg/xray.resourceXrayRepositoryConfig.func14({0xddb5e8, 0xc000060b40}, 0xc00030e480, {0xc0b420?, 0xc000487740})
        github.com/jfrog/terraform-provider-xray/pkg/xray/resource_xray_repository_config.go:483 +0x64a
github.com/jfrog/terraform-provider-shared/util/sdk.applyTelemetry.func1({0xddb5e8?, 0xc000060b40}, 0x0?, {0xc0b420?, 0xc000487740})
        github.com/jfrog/[email protected]/util/sdk/sdk.go:234 +0x263
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc00049ec40, {0xddb620, 0xc000518180}, 0xd?, {0xc0b420, 0xc000487740})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:750 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc00049ec40, {0xddb620, 0xc000518180}, 0xc0000b7040, {0xc0b420, 0xc000487740})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:1044 +0x59e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc00030da58, {0xddb620?, 0xc000518030?}, 0xc0003907c0)
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:616 +0x497
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc0004b63c0, {0xddb620?, 0xc0002cea80?}, 0xc000176660)
        github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:751 +0x49e
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0xc60400?, 0xc0004b63c0}, {0xddb620, 0xc0002cea80}, 0xc000368070, 0x0)
        github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:386 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00047c000, {0xdde2a0, 0xc0001024e0}, 0xc000355b00, 0xc000487560, 0x128ef90, 0x0)
        google.golang.org/[email protected]/server.go:1337 +0xde3
google.golang.org/grpc.(*Server).handleStream(0xc00047c000, {0xdde2a0, 0xc0001024e0}, 0xc000355b00, 0x0)
        google.golang.org/[email protected]/server.go:1714 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.1()
        google.golang.org/[email protected]/server.go:959 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/[email protected]/server.go:957 +0x18c

Error: The terraform-provider-xray_v2.0.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.

And x-ray config of repository is like this:

terraform {
  required_providers {
    artifactory = {
      source  = "registry.terraform.io/jfrog/artifactory"
      version = ">= 6.10.1, < 9.0.0"
    }
    xray = {
      source  = "registry.terraform.io/jfrog/xray"
      version = ">= 1.11.1, <= 2.0.0"
    }
  }
}

resource "artifactory_local_maven_repository" "repo" {
  key                  = var.key
  repo_layout_ref      = var.layout_ref
  description          = "**MANAGED BY TERRAFORM** ${var.description}"
  notes                = "Owner: ${var.owner}"
  includes_pattern     = var.includes_pattern
  excludes_pattern     = var.excludes_pattern
  priority_resolution  = var.priority_resolution
  handle_releases      = var.handle_releases
  handle_snapshots     = var.handle_snapshots
  property_sets        = ["artifactory"]
  download_direct      = var.download_direct
  xray_index           = var.xray_index
  blacked_out          = var.blacked_out
  checksum_policy_type = var.checksum_policy_type
}

resource "xray_repository_config" "local-maven-xray-config" {
  provider  = xray
  repo_name = var.key
  config {
    retention_in_days   = 90
  }

Requirements for and issue
Artifactory 7.63.12 (with Enterprise Plus license) and Xray 3.81.8.
TF 1.0.2

Expected behavior
Absence of errors during upgrade attempt.

Additional context
Add any other context about the problem here.

@aserzhankou aserzhankou added the bug Something isn't working label Oct 31, 2023
@alexhung alexhung assigned alexhung and unassigned danielmkn Oct 31, 2023
@alexhung
Copy link
Member

@aserzhankou I tried to reproduce this crash but so far unable to. I started out with Xray provider 1.12.0 and created one local repo and a repo config:

terraform {
  required_providers {
    artifactory = {
      source  = "registry.terraform.io/jfrog/artifactory"
      version = "9.7.2"
    }
    xray = {
      source  = "registry.terraform.io/jfrog/xray"
      version = "1.12.0"
    }
  }
}

resource "artifactory_local_generic_repository" "local-generic-repo" {
  key        = "local-generic-repo"
  xray_index = true
}

resource "xray_repository_config" "local-generic-xray-config" {
  repo_name = artifactory_local_generic_repository.local-generic-repo.key

  config {
    retention_in_days = 90
  }
}

Here's the shell output:

alexh@alexh-mac terraform-provider-xray % terraform init -upgrade

Initializing the backend...

Initializing provider plugins...
- Finding jfrog/artifactory versions matching "9.7.2"...
- Finding jfrog/xray versions matching "1.12.0"...
- Installing jfrog/xray v1.12.0...
- Installed jfrog/xray v1.12.0 (signed by a HashiCorp partner, key ID 2FA4D2A520237FA7)
- Using previously-installed jfrog/artifactory v9.7.2

Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html

Terraform has made some changes to the provider dependency selections recorded
in the .terraform.lock.hcl file. Review those changes and commit them to your
version control system if they represent changes you intended to make.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
alexh@alexh-mac terraform-provider-xray % terraform apply

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # artifactory_local_generic_repository.local-generic-repo will be created
  + resource "artifactory_local_generic_repository" "local-generic-repo" {
      + blacked_out          = false
      + cdn_redirect         = false
      + id                   = (known after apply)
      + includes_pattern     = "**/*"
      + key                  = "local-generic-repo"
      + package_type         = (known after apply)
      + priority_resolution  = false
      + project_environments = (known after apply)
      + repo_layout_ref      = "simple-default"
      + xray_index           = true
    }

  # xray_repository_config.local-generic-xray-config will be created
  + resource "xray_repository_config" "local-generic-xray-config" {
      + id        = (known after apply)
      + repo_name = "local-generic-repo"

      + config {
          + retention_in_days = 90
        }
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

artifactory_local_generic_repository.local-generic-repo: Creating...
artifactory_local_generic_repository.local-generic-repo: Creation complete after 0s [id=local-generic-repo]
xray_repository_config.local-generic-xray-config: Creating...
xray_repository_config.local-generic-xray-config: Creation complete after 0s [id=local-generic-repo]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

Then I upgrade the Xray provider version in HCL to 2.0.1 and run terraform plan:

alexh@alexh-mac terraform-provider-xray % terraform init -upgrade

Initializing the backend...

Initializing provider plugins...
- Finding jfrog/artifactory versions matching "9.7.2"...
- Finding jfrog/xray versions matching "2.0.1"...
- Using previously-installed jfrog/artifactory v9.7.2
- Installing jfrog/xray v2.0.1...
- Installed jfrog/xray v2.0.1 (signed by a HashiCorp partner, key ID 2FA4D2A520237FA7)

Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html

Terraform has made some changes to the provider dependency selections recorded
in the .terraform.lock.hcl file. Review those changes and commit them to your
version control system if they represent changes you intended to make.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
alexh@alexh-mac terraform-provider-xray % terraform plan
artifactory_local_generic_repository.local-generic-repo: Refreshing state... [id=local-generic-repo]
xray_repository_config.local-generic-xray-config: Refreshing state... [id=local-generic-repo]

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

I'm using Terraform 1.6.3 so may be that affected my result. Can you try to upgrade to the latest Terraform?

@alexhung
Copy link
Member

@aserzhankou ok, I managed to reproduce this issue. Working on a fix.

alexhung added a commit that referenced this issue Oct 31, 2023
Fix crash when upgrading from 1.12.0 to >=1.15.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants