cli icon indicating copy to clipboard operation
cli copied to clipboard

cf delete-org fails with "index out of range [0] with length 0"

Open nictas opened this issue 6 years ago • 7 comments

  • [x] I reviewed open and closed github issues that may be related to my problem.
  • [x] I tried updating to the latest version of the CF CLI to see if it fixed my problem.
  • [x] I attempted to run the command with CF_TRACE=1 to help debug the issue.
  • [x] I am reporting a bug that others will be able to reproduce.

Describe the bug and the command you saw an issue with I was trying to delete an organization via cf delete-org my-org -f.

What happened This is the error that I ran into:

REQUEST: [2020-10-20T11:22:18Z]
GET /v3/organizations?names=my-org HTTP/1.1
Host: api.cf.xxx.com
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
User-Agent: cf/7.1.0+4c3168f9a.2020-09-09 (go1.13.8; amd64 linux)

RESPONSE: [2020-10-20T11:22:19Z]
HTTP/1.1 200 OK
Content-Length: 1594
Content-Type: application/json; charset=utf-8
Date: Tue, 20 Oct 2020 11:22:18 GMT
Referrer-Policy: strict-origin-when-cross-origin
Server: nginx
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload;
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Ratelimit-Limit: 40000
X-Ratelimit-Remaining: 38958
X-Ratelimit-Reset: 1603194348
X-Runtime: 0.015893
X-Vcap-Request-Id: 17cbde5c-687e-4edd-4077-036450ab94b3::e759a576-8139-4d35-98b9-99a131482619
X-Xss-Protection: 1; mode=block
{
  "pagination": {
    "first": {
      "href": "https://api.cf.xxx.com/v3/organizations?names=my-org&page=1&per_page=50"
    },
    "last": {
      "href": "https://api.cf.xxx.com/v3/organizations?names=my-org&page=1&per_page=50"
    },
    "next": null,
    "previous": null,
    "total_pages": 1,
    "total_results": 1
  },
  "resources": [
    {
      "created_at": "2020-10-13T12:04:34Z",
      "guid": "7af7622f-504a-4c2c-9254-9ef48d06c107",
      "links": {
        "default_domain": {
          "href": "https://api.cf.xxx.com/v3/organizations/7af7622f-504a-4c2c-9254-9ef48d06c107/domains/default"
        },
        "domains": {
          "href": "https://api.cf.xxx.com/v3/organizations/7af7622f-504a-4c2c-9254-9ef48d06c107/domains"
        },
        "quota": {
          "href": "https://api.cf.xxx.com/v3/organization_quotas/2b8d92ec-b529-40b7-b949-b61907ea1c3d"
        },
        "self": {
          "href": "https://api.cf.xxx.com/v3/organizations/7af7622f-504a-4c2c-9254-9ef48d06c107"
        }
      },
      "metadata": {
        "annotations": {},
        "labels": {}
      },
      "name": "my-org",
      "relationships": {
        "quota": {
          "data": {
            "guid": "2b8d92ec-b529-40b7-b949-b61907ea1c3d"
          }
        }
      },
      "suspended": false,
      "updated_at": "2020-10-20T11:18:23Z"
    }
  ]
}


REQUEST: [2020-10-20T11:22:19Z]
DELETE /v3/organizations/7af7622f-504a-4c2c-9254-9ef48d06c107 HTTP/1.1
Host: api.cf.xxx.com
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
User-Agent: cf/7.1.0+4c3168f9a.2020-09-09 (go1.13.8; amd64 linux)

RESPONSE: [2020-10-20T11:22:19Z]
HTTP/1.1 202 Accepted
Content-Length: 0
Content-Type: application/json
Date: Tue, 20 Oct 2020 11:22:19 GMT
Location: https://api.cf.xxx.com/v3/jobs/e9609f43-78d2-4b0b-985e-630afcff3696
Referrer-Policy: strict-origin-when-cross-origin
Server: nginx
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload;
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Ratelimit-Limit: 40000
X-Ratelimit-Remaining: 38957
X-Ratelimit-Reset: 1603194348
X-Runtime: 0.053481
X-Vcap-Request-Id: 5e20e9f5-9b33-462a-511a-81087e412b0c::3fe5a423-4d20-4e2f-a660-142c6e5527f7
X-Xss-Protection: 1; mode=block

REQUEST: [2020-10-20T11:22:19Z]
GET /v3/jobs/e9609f43-78d2-4b0b-985e-630afcff3696 HTTP/1.1
Host: api.cf.xxx.com
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
User-Agent: cf/7.1.0+4c3168f9a.2020-09-09 (go1.13.8; amd64 linux)

RESPONSE: [2020-10-20T11:22:19Z]
HTTP/1.1 200 OK
Content-Length: 531
Content-Type: application/json; charset=utf-8
Date: Tue, 20 Oct 2020 11:22:19 GMT
Referrer-Policy: strict-origin-when-cross-origin
Server: nginx
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload;
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Ratelimit-Limit: 40000
X-Ratelimit-Remaining: 38956
X-Ratelimit-Reset: 1603194348
X-Runtime: 0.007650
X-Vcap-Request-Id: fbcadb87-7510-4196-75a0-6283f54b76e4::1b0626b4-b832-43d2-9786-128c53f8a939
X-Xss-Protection: 1; mode=block
{
  "created_at": "2020-10-20T11:22:19Z",
  "errors": null,
  "guid": "e9609f43-78d2-4b0b-985e-630afcff3696",
  "links": {
    "organization": {
      "href": "https://api.cf.xxx.com/v3/organizations/7af7622f-504a-4c2c-9254-9ef48d06c107"
    },
    "self": {
      "href": "https://api.cf.xxx.com/v3/jobs/e9609f43-78d2-4b0b-985e-630afcff3696"
    }
  },
  "operation": "organization.delete",
  "state": "PROCESSING",
  "updated_at": "2020-10-20T11:22:19Z",
  "warnings": null
}


REQUEST: [2020-10-20T11:22:22Z]
GET /v3/jobs/e9609f43-78d2-4b0b-985e-630afcff3696 HTTP/1.1
Host: api.cf.xxx.com
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
User-Agent: cf/7.1.0+4c3168f9a.2020-09-09 (go1.13.8; amd64 linux)

RESPONSE: [2020-10-20T11:22:22Z]
HTTP/1.1 200 OK
Content-Length: 531
Content-Type: application/json; charset=utf-8
Date: Tue, 20 Oct 2020 11:22:22 GMT
Referrer-Policy: strict-origin-when-cross-origin
Server: nginx
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload;
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Ratelimit-Limit: 40000
X-Ratelimit-Remaining: 38954
X-Ratelimit-Reset: 1603194348
X-Runtime: 0.017074
X-Vcap-Request-Id: dee758d3-1c98-4535-42d2-1828da7705eb::5ae20a83-6053-4d5e-96d8-245b631cf8de
X-Xss-Protection: 1; mode=block
{
  "created_at": "2020-10-20T11:22:19Z",
  "errors": null,
  "guid": "e9609f43-78d2-4b0b-985e-630afcff3696",
  "links": {
    "organization": {
      "href": "https://api.cf.xxx.com/v3/organizations/7af7622f-504a-4c2c-9254-9ef48d06c107"
    },
    "self": {
      "href": "https://api.cf.xxx.com/v3/jobs/e9609f43-78d2-4b0b-985e-630afcff3696"
    }
  },
  "operation": "organization.delete",
  "state": "PROCESSING",
  "updated_at": "2020-10-20T11:22:19Z",
  "warnings": null
}


REQUEST: [2020-10-20T11:22:25Z]
GET /v3/jobs/e9609f43-78d2-4b0b-985e-630afcff3696 HTTP/1.1
Host: api.cf.xxx.com
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
User-Agent: cf/7.1.0+4c3168f9a.2020-09-09 (go1.13.8; amd64 linux)

RESPONSE: [2020-10-20T11:22:25Z]
HTTP/1.1 200 OK
Content-Length: 527
Content-Type: application/json; charset=utf-8
Date: Tue, 20 Oct 2020 11:22:25 GMT
Referrer-Policy: strict-origin-when-cross-origin
Server: nginx
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload;
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Ratelimit-Limit: 40000
X-Ratelimit-Remaining: 38952
X-Ratelimit-Reset: 1603194348
X-Runtime: 0.008243
X-Vcap-Request-Id: 666821af-aaff-4715-4b7c-cc85e91e78e8::a21ab1df-6616-45bd-a82b-20ed0a0006b6
X-Xss-Protection: 1; mode=block
{
  "created_at": "2020-10-20T11:22:19Z",
  "errors": null,
  "guid": "e9609f43-78d2-4b0b-985e-630afcff3696",
  "links": {
    "organization": {
      "href": "https://api.cf.xxx.com/v3/organizations/7af7622f-504a-4c2c-9254-9ef48d06c107"
    },
    "self": {
      "href": "https://api.cf.xxx.com/v3/jobs/e9609f43-78d2-4b0b-985e-630afcff3696"
    }
  },
  "operation": "organization.delete",
  "state": "FAILED",
  "updated_at": "2020-10-20T11:22:23Z",
  "warnings": null
}



		Something unexpected happened. This is a bug in cf.

		Please re-run the command that caused this exception with the environment
		variable CF_TRACE set to true.

		Also, please update to the latest cli and try the command again:
		https://code.cloudfoundry.org/cli/releases

		Please create an issue at: https://code.cloudfoundry.org/cli/issues

		Include the below information when creating the issue:

		Command
		cf delete-org my-org -f

		CLI Version
		7.1.0+4c3168f9a.2020-09-09

		Error
		runtime error: index out of range [0] with length 0

		Stack Trace
			goroutine 1 [running]:
	code.cloudfoundry.org/cli/util/panichandler.HandlePanic()
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/util/panichandler/handler.go:19 +0x81
	panic(0x10fa4a0, 0xc0007624c0)
		/usr/local/go/src/runtime/panic.go:679 +0x1b2
	code.cloudfoundry.org/cli/api/cloudcontroller/ccv3.(*Client).PollJob(0xc00003d8c0, 0xc0008bb2c0, 0x5c, 0x0, 0x0, 0x0, 0x0, 0x0)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/job.go:109 +0x5b8
	code.cloudfoundry.org/cli/actor/v7action.Actor.DeleteOrganization(0x13bc640, 0xc00003d8c0, 0x7ff23e459b50, 0xc0002d2000, 0x138a1e0, 0xc000297840, 0x139cc60, 0xc0003e60e0, 0x137bca0, 0xc00001cbd0, ...)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/actor/v7action/organization.go:103 +0x293
	code.cloudfoundry.org/cli/command/v7.(*DeleteOrgCommand).Execute(0x1c22e08, 0xc00028d3e0, 0x0, 0x3, 0xc0002c0000, 0x0)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/command/v7/delete_org_command.go:49 +0x295
	code.cloudfoundry.org/cli/util/command_parser.(*CommandParser).executionWrapper(0xc00038a010, 0x7ff23e64d778, 0x1c22e08, 0xc00028d3e0, 0x0, 0x3, 0x0, 0x0)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/util/command_parser/command_parser.go:93 +0x270
	code.cloudfoundry.org/cli/vendor/github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc0005320e0, 0xc0000d8050, 0x3, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/vendor/github.com/jessevdk/go-flags/parser.go:331 +0x89c
	code.cloudfoundry.org/cli/util/command_parser.(*CommandParser).parse(0xc00038a010, 0xc0000d8050, 0x3, 0x3, 0x100e680, 0x1c21340, 0x0, 0x1c15840, 0xc0004e5e70)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/util/command_parser/command_parser.go:221 +0xe0
	code.cloudfoundry.org/cli/util/command_parser.(*CommandParser).ParseCommandFromArgs(...)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/util/command_parser/command_parser.go:57
	main.main()
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/main.go:40 +0x19e
	
	goroutine 5 [syscall]:
	os/signal.signal_recv(0x0)
		/usr/local/go/src/runtime/sigqueue.go:147 +0x9c
	os/signal.loop()
		/usr/local/go/src/os/signal/signal_unix.go:23 +0x22
	created by os/signal.init.0
		/usr/local/go/src/os/signal/signal_unix.go:29 +0x41
	
	goroutine 826 [chan receive]:
	code.cloudfoundry.org/cli/util/configv3.catchSignal(0xc00076a120, 0xc00075c6a0, 0x1e)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/util/configv3/write_config.go:55 +0x34
	created by code.cloudfoundry.org/cli/util/configv3.(*Config).WriteConfig
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/util/configv3/write_config.go:40 +0x2c9
	
	goroutine 595 [IO wait]:
	internal/poll.runtime_pollWait(0x7ff23e644d68, 0x72, 0xffffffffffffffff)
		/usr/local/go/src/runtime/netpoll.go:184 +0x55
	internal/poll.(*pollDesc).wait(0xc000488398, 0x72, 0x1300, 0x138f, 0xffffffffffffffff)
		/usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x45
	internal/poll.(*pollDesc).waitRead(...)
		/usr/local/go/src/internal/poll/fd_poll_runtime.go:92
	internal/poll.(*FD).Read(0xc000488380, 0xc000177500, 0x138f, 0x138f, 0x0, 0x0, 0x0)
		/usr/local/go/src/internal/poll/fd_unix.go:169 +0x1cf
	net.(*netFD).Read(0xc000488380, 0xc000177500, 0x138f, 0x138f, 0x203000, 0x0, 0x1382)
		/usr/local/go/src/net/fd_unix.go:202 +0x4f
	net.(*conn).Read(0xc00000e010, 0xc000177500, 0x138f, 0x138f, 0x0, 0x0, 0x0)
		/usr/local/go/src/net/net.go:184 +0x68
	crypto/tls.(*atLeastReader).Read(0xc0005a6da0, 0xc000177500, 0x138f, 0x138f, 0x3, 0x8, 0xc0005c08a0)
		/usr/local/go/src/crypto/tls/conn.go:780 +0x60
	bytes.(*Buffer).ReadFrom(0xc000152cd8, 0x136d040, 0xc0005a6da0, 0x409d05, 0x10237a0, 0x1155060)
		/usr/local/go/src/bytes/buffer.go:204 +0xb4
	crypto/tls.(*Conn).readFromUntil(0xc000152a80, 0x136d400, 0xc00000e010, 0x5, 0xc00000e010, 0x2b)
		/usr/local/go/src/crypto/tls/conn.go:802 +0xec
	crypto/tls.(*Conn).readRecordOrCCS(0xc000152a80, 0x0, 0x0, 0x3)
		/usr/local/go/src/crypto/tls/conn.go:609 +0x124
	crypto/tls.(*Conn).readRecord(...)
		/usr/local/go/src/crypto/tls/conn.go:577
	crypto/tls.(*Conn).Read(0xc000152a80, 0xc0004fa000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
		/usr/local/go/src/crypto/tls/conn.go:1255 +0x161
	net/http.(*persistConn).Read(0xc0003e4120, 0xc0004fa000, 0x1000, 0x1000, 0xc0003ac180, 0xc0005c0c20, 0x404d15)
		/usr/local/go/src/net/http/transport.go:1758 +0x75
	bufio.(*Reader).fill(0xc0000d46c0)
		/usr/local/go/src/bufio/bufio.go:100 +0x103
	bufio.(*Reader).Peek(0xc0000d46c0, 0x1, 0x0, 0x0, 0x1, 0xc0002eb900, 0x0)
		/usr/local/go/src/bufio/bufio.go:138 +0x4f
	net/http.(*persistConn).readLoop(0xc0003e4120)
		/usr/local/go/src/net/http/transport.go:1911 +0x1d6
	created by net/http.(*Transport).dialConn
		/usr/local/go/src/net/http/transport.go:1580 +0xb0d
	
	goroutine 596 [select]:
	net/http.(*persistConn).writeLoop(0xc0003e4120)
		/usr/local/go/src/net/http/transport.go:2210 +0x123
	created by net/http.(*Transport).dialConn
		/usr/local/go/src/net/http/transport.go:1581 +0xb32
	

		Your Platform Details
		e.g. Mac OS X 10.11, Windows 8.1 64-bit, Ubuntu 14.04.3 64-bit

		Shell
		e.g. Terminal, iTerm, Powershell, Cygwin, gnome-terminal, terminator

Note that I've had to replace the API host and the organization name with dummy values.

Expected behavior I expected the organization to either be deleted or the command to fail with a better error message explaining what failed and why.

Exact Steps To Reproduce I'm not sure. I tried to reproduce the error with a different organization, but its deletion worked without any issues. I assume that the problem reproduces only when the errors field of the response of GET /v3/jobs/:guid is null. If so, is this also an issue with the CC? Shouldn't there always be an error description?

Provide more context

  • Platform: Linux 3542031f-8edc-4156-53c7-97236cb8d76e 4.4.0-142-generic #168-Ubuntu SMP Wed Jan 16 21:00:45 UTC 2019 x86_64 GNU/Linux
  • CLI version: 7.1.0+4c3168f9a.2020-09-09
  • CC API version: 2.153.0

nictas avatar Oct 20 '20 11:10 nictas

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/175352747

The labels on this github issue will be updated when the story is started.

cf-gitbot avatar Oct 20 '20 11:10 cf-gitbot

Hey @nictas - Thanks for reporting this issue. Two things:

  1. We may have mishandled this type of error and we'd like to investigate further
  2. It's not completely clear to us what's happened (what caused CAPI to fail). If possible, could you share the logs from the CAPI api from the time period when this failure occurred.

We look forward to hearing back from you!

heyjcollins avatar Oct 26 '20 16:10 heyjcollins

Thanks for reporting the issue. Our understanding is that the CLI is just polling the CAPI for the status of the job, and the job failed. As such we believe this is a CAPI issue. Please file an issue with https://github.com/cloudfoundry/cloud_controller_ng for further research on this issue.

jpalmerpivotal avatar Oct 28 '20 23:10 jpalmerpivotal

Feel free to reopen the issue if you believe it is with the CF CLI.

jpalmerpivotal avatar Oct 28 '20 23:10 jpalmerpivotal

Our understanding is that the CLI is just polling the CAPI for the status of the job, and the job failed. As such we believe this is a CAPI issue.

Hey @jpalmerpivotal! I think there are two issues here:

  1. CAPI is (may be?) sending the CLI a malformed or at least unexpected response.
  2. The CLI panics because of the response.

The first issue may be on CAPI to resolve, but do you think we can at least guard against panic when we receive a malformed response from CAPI?

staylor14 avatar Oct 29 '20 17:10 staylor14

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/175501233

The labels on this github issue will be updated when the story is started.

cf-gitbot avatar Oct 29 '20 17:10 cf-gitbot

We recently released v7.2.0, which should contain a fix for this issue. Thanks for your help!

reidmit avatar Dec 18 '20 20:12 reidmit