cloudfoundry / cli

The official command line client for Cloud Foundry
https://docs.cloudfoundry.org/cf-cli
Apache License 2.0
1.75k stars 929 forks source link

Panic when using `cf curl` when uaa is down #1838

Closed ewrenn8 closed 1 month ago

ewrenn8 commented 5 years ago

Describe the bug and the command you saw an issue with Cf curl panics if there is no uaa and the auth token is expired.

To Reproduce Steps to reproduce the behavior; include the exact CLI commands and verbose output:

  1. cf login as admin
  2. bosh stop uaa
  3. Decode Auth token from ~/.cf/config.json and wait until the expiration time
  4. run cf curl v3/

Relevant Stack Trace

± ew |master ✓| → cf curl /v3

        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 curl /v3

        CLI Version
        6.47.1+0921a21b7.2019-10-18

        Error
        runtime error: invalid memory address or nil pointer dereference

        Stack Trace
            goroutine 1 [running]:
    code.cloudfoundry.org/cli/util/panichandler.HandlePanic()
        /Users/pivotal/concourse/volumes/live/457944c4-1b81-4699-4c45-d4cad5ec4847/volume/gopath/src/code.cloudfoundry.org/cli/util/panichandler/handler.go:19 +0x81
    panic(0x1a230a0, 0x24f5ee0)
        /usr/local/Cellar/go@1.12/1.12.10/libexec/src/runtime/panic.go:522 +0x1b5
    code.cloudfoundry.org/cli/cf/api.CloudControllerCurlRepository.Request(0x2b51d30, 0xc0001e8200, 0x2b52020, 0xc0001cebb0, 0x1ba8400, 0x1, 0x12a05f200, 0x0, 0x0, 0x0, ...)
        /Users/pivotal/concourse/volumes/live/457944c4-1b81-4699-4c45-d4cad5ec4847/volume/gopath/src/code.cloudfoundry.org/cli/cf/api/curl.go:62 +0x60f
    code.cloudfoundry.org/cli/cf/commands.(*Curl).Execute(0xc000090400, 0x1d485e0, 0xc0001e8780, 0x1d485e0, 0xc0001e8780)
        /Users/pivotal/concourse/volumes/live/457944c4-1b81-4699-4c45-d4cad5ec4847/volume/gopath/src/code.cloudfoundry.org/cli/cf/commands/curl.go:111 +0x29d
    code.cloudfoundry.org/cli/cf/cmd.Main(0x0, 0x0, 0xc0000f0000, 0x3, 0x3)
        /Users/pivotal/concourse/volumes/live/457944c4-1b81-4699-4c45-d4cad5ec4847/volume/gopath/src/code.cloudfoundry.org/cli/cf/cmd/cmd.go:122 +0xc94
    main.handleError(0x1d15b40, 0x2530ec0, 0x1d2e280, 0xc00011a4d0, 0x1d15b40, 0x2530ec0)
        /Users/pivotal/concourse/volumes/live/457944c4-1b81-4699-4c45-d4cad5ec4847/volume/gopath/src/code.cloudfoundry.org/cli/main.go:271 +0x504
    main.executionWrapper(0x2b51bd0, 0x251d950, 0xc0001005a0, 0x0, 0x2, 0x0, 0x0)
        /Users/pivotal/concourse/volumes/live/457944c4-1b81-4699-4c45-d4cad5ec4847/volume/gopath/src/code.cloudfoundry.org/cli/main.go:249 +0x2a9
    code.cloudfoundry.org/cli/vendor/github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc0001c6150, 0xc0000f0010, 0x2, 0x2, 0xc0002ffee0, 0x7035c5709e7ef34e, 0x2510120, 0xc000000180, 0xc0000f0f30)
        /Users/pivotal/concourse/volumes/live/457944c4-1b81-4699-4c45-d4cad5ec4847/volume/gopath/src/code.cloudfoundry.org/cli/vendor/github.com/jessevdk/go-flags/parser.go:331 +0x883
    main.parse(0xc0000f0010, 0x2, 0x2, 0x1a28100, 0x251bc40, 0xc0000ba058)
        /Users/pivotal/concourse/volumes/live/457944c4-1b81-4699-4c45-d4cad5ec4847/volume/gopath/src/code.cloudfoundry.org/cli/main.go:61 +0xaa
    main.main()
        /Users/pivotal/concourse/volumes/live/457944c4-1b81-4699-4c45-d4cad5ec4847/volume/gopath/src/code.cloudfoundry.org/cli/main.go:49 +0xa3

When UAA can't be found, this line returns an error, meaning the response is <nil> while err is a HTTPNotFoundError. After executing this line err gets reset to <nil>, allowing us to call .Body on a nil pointer

cf-gitbot commented 5 years ago

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

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

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

abbyachau commented 5 years ago

Hey thanks @ewrenn8, for creating this issue. We'll try to review some time soon.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed.

a-b commented 1 month ago

Thank you for your submission. If you still run into this issue with the latest CLI v8, please open a new ticket.