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

cli: COCKROACH_URL env var is broken #40747

Closed
bdarnell opened this issue Sep 13, 2019 · 2 comments · Fixed by #40824
Closed

cli: COCKROACH_URL env var is broken #40747

bdarnell opened this issue Sep 13, 2019 · 2 comments · Fixed by #40824
Assignees
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. S-2-temp-unavailability Temp crashes or other availability problems. Can be worked around or resolved by restarting.

Comments

@bdarnell
Copy link
Contributor

Describe the problem

The COCKROACH_URL environment variable is supposed to be equivalent to the --url flag, but using it causes a panic.

To Reproduce

cockroach sql --url works:

[bdarnell@ben-crl ~]$ cockroach sql --url=postgresql://[email protected]:26257?sslmode=disable
# Welcome to the cockroach SQL interface.
# All statements must be terminated by a semicolon.
# To exit: CTRL + D.
#
# Server version: CockroachDB CCL v19.1.4 (x86_64-apple-darwin14, built 2019/08/06 15:29:00, go1.11.6) (same version as client)
# Cluster ID: 06389009-5b11-4adb-97dc-a52b72a0f0d5
#
# Enter \? for a brief introduction.
#
[email protected]:26257/defaultdb> ^D   

cockroach sql with a COCKROACH_URL env var panics:

warning: --url specifies user/password, but command "sql" does not accept user/password details - details ignored
panic: invalid argument "postgresql://[email protected]:26257?sslmode=disable" for "--url" flag: extracting host/port: no such flag -host

goroutine 1 [running]:
github.com/cockroachdb/cockroach/pkg/cli.setFlagFromEnv(0xc00082a200, 0x6afda86, 0x3, 0x0, 0x0, 0x6b1035e, 0xd, 0x6bd480d, 0xa1)
	/go/src/github.com/cockroachdb/cockroach/pkg/cli/flags.go:91 +0xa0
github.com/cockroachdb/cockroach/pkg/cli.VarFlag(0xc00082a200, 0x727fbc0, 0xc00036a860, 0x6afda86, 0x3, 0x0, 0x0, 0x6b1035e, 0xd, 0x6bd480d, ...)
	/go/src/github.com/cockroachdb/cockroach/pkg/cli/flags.go:131 +0xfc
github.com/cockroachdb/cockroach/pkg/cli.init.5()
	/go/src/github.com/cockroachdb/cockroach/pkg/cli/flags.go:507 +0x29c4

Expected behavior

The env var should work in the same way as the command-line flag.

Environment:

  • CockroachDB version 19.1.4
  • Server OS: macOS
  • Client app cockroach sql

Additional context

I think we should be encouraging the use of COCKROACH_URL in documentation, but it has to work first.

@knz knz added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. S-2-temp-unavailability Temp crashes or other availability problems. Can be worked around or resolved by restarting. A-cli labels Sep 17, 2019
@knz
Copy link
Contributor

knz commented Sep 17, 2019

The cause for this is that the logic tries to process the env var immediately as the flag set is being constructed, but the processing of the env var requires to wait until all the flag set has been constructed.

We can fix this either by tweaking the ordering (define the url flag after the others) or by processing all the env var at the end (this is more robust). Will send PR.

@knz
Copy link
Contributor

knz commented Sep 17, 2019

Related issue upstream: spf13/cobra#961

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. S-2-temp-unavailability Temp crashes or other availability problems. Can be worked around or resolved by restarting.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants