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

pdctl: verify pd address #528

Merged
merged 7 commits into from
Feb 21, 2017
Merged

pdctl: verify pd address #528

merged 7 commits into from
Feb 21, 2017

Conversation

nolouch
Copy link
Contributor

@nolouch nolouch commented Feb 17, 2017

if err != nil {
return err
}
if reps.StatusCode != http.StatusOK {
Copy link
Contributor

Choose a reason for hiding this comment

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

must read all response body and close

pdctl/ctl.go Outdated
command.InitPDClient(rootCmd)
err := command.InitPDClient(rootCmd)
if err != nil {
return err.Error(), err
Copy link
Contributor

Choose a reason for hiding this comment

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

why return err.Error() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this string will print.

Copy link
Contributor

Choose a reason for hiding this comment

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

why not check error and print the error directly?

@@ -87,7 +87,9 @@ func loop() {
}
continue
}

if line == "exit" {
Copy link
Contributor

Choose a reason for hiding this comment

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

split it to another PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if InitPDClient meet error, it will return error directly without execute the command. so I move exit to here.

command.InitPDClient(rootCmd)
err := command.InitPDClient(rootCmd)
if err != nil {
fmt.Println(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

should exit here directly?

Copy link
Contributor

@siddontang siddontang left a comment

Choose a reason for hiding this comment

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

LGTM

@siddontang
Copy link
Contributor

PTAL @disksing

}
defer reps.Body.Close()
if reps.StatusCode != http.StatusOK {
ioutil.ReadAll(reps.Body)
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't have to read it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If not read, the connection FD will not close even you call body close later. I remember this is a pitfall before, but don't know go improves it or not.

Btw, We should call ioutil.ReadAll(reps.Body) before the status check.

@disksing
Copy link
Contributor

LGTM

@nolouch nolouch merged commit c306fe8 into master Feb 21, 2017
@nolouch nolouch deleted the shuning/verify-address branch February 21, 2017 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pd-ctl: throw error if connect with wrong pd address
3 participants