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

etcdctl: fix exit status of endpoint command #8316

Closed
wants to merge 1 commit into from
Closed

etcdctl: fix exit status of endpoint command #8316

wants to merge 1 commit into from

Conversation

koorgoo
Copy link
Contributor

@koorgoo koorgoo commented Jul 27, 2017

Fixes #8295. Based on channels solution from discussion on #8307.

@koorgoo
Copy link
Contributor Author

koorgoo commented Jul 27, 2017

@heyitsanthony take a look, please.

close(errc)

// exit with non-zero exit status in case of errors.
os.Exit(<-errCountc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the exit code shouldn't change based on the number of errors; ExitWithError(ExitError, fmt.Errorf("unhealthy cluster")) would be more consistent with the rest of etcdctl

defer close(errCountc)

// drain errors channel until it is closed.
go func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this extra concurrency isn't necessary since errc is already buffered-- keep it simple by doing the error pass after the other goroutine complete:

wg.Wait()
close(errc)
errs := false
for err := range errc {
    if err != nil {
        errs = true
        fmt.Fprintln(os.Stderr, err)
    }   
}
if errs {
    ExitWithError(ExitError, fmt.Errorf("unhealthy cluster"))
}


for _, cfg := range cfgs {
wg.Add(1)
go func(cfg *v3.Config) {
go func(cfg *v3.Config, errc chan<- error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line can stay the same-- errc is already captured by the closure

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

Successfully merging this pull request may close these issues.

3 participants