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

fix: pouch pull image decode exception error #160

Merged
merged 1 commit into from Nov 28, 2017

Conversation

HusterWan
Copy link
Contributor

@HusterWan HusterWan commented Nov 26, 2017

Signed-off-by: HusterWan zirenwan@gmail.com

1.Describe what this PR did
fix json decode error when pouch pull image error

2.Does this pull request fix one issue?
fixes #123 .

3.Describe how you did it
return error message through stream body when pouch pull image

4.Describe how to verify it
excute command line: pouch pull busybox, will print error information
pouch:
image
pouchd
image

5.Special notes for reviews
https://golang.org/pkg/net/http/#ResponseWriter

  1. WriteHeader can only be called once
  2. before call Write, if not call WriteHeader before, will call WriteHeader(http.StatusOK) first

there is a goroutine to send downloading progress information to client when pouch pull image, so when goroutine call Write once, the http header code will be set 200, later call WriteHeader(500) will print error: call multi WriteHeader, and 500 will not send to client.

so we should not only use http code to judge if pull is ok, but contains error information in ProgressMessage, then client can deal with error information appropriately

@pouchrobot pouchrobot added kind/bug This is bug report for project size/L labels Nov 26, 2017
@pouchrobot
Copy link
Collaborator

We found this is your first time to contribute to Pouch, @HusterWan
👏 We really appreciate it.
Just remind that you have read the contribution guide: https://github.com/alibaba/pouch/blob/master/CONTRIBUTING.md
If you didn't, you should do that first. If done, welcome again and please enjoy hacking! 🍻

@skoowoo
Copy link
Contributor

skoowoo commented Nov 27, 2017

Thanks for your "PR", Reviewing....

@skoowoo
Copy link
Contributor

skoowoo commented Nov 27, 2017

the diff is okay to handle the errors.

There are some designs that I want to discuss them with you.

  1. the format of jsonstream is a underlying object, it is visible by the jsonstream only, avoid to be called by others. Now there is only default format, but later, We will add docker's progress format .

  2. the error message of pull image may be returned to CLI as same as the progress message. We can put the error message into jsonstream in ctrd.
    e.g.
    go func() {
    if err := c.fetchProgress(pctx, ongoing, stream); err != nil {
    logrus.Errorf("failed to get pull's progress: %v", err)
    }
    close(wait)

     logrus.Infof("fetch progress exited, ref: %s.", ref)
    

    }()

    // start to pull image.
    img, err := c.pullImage(ctx, ref, options)

    // cancel fetch progress befor handle error.
    cancelProgress()
    <-wait
    defer stream.Close()

    if err != nil {
             stream.WriteObject(<the error message>)  <=========== here
     return nil, err
    

    }

  3. I think that We don't need to define "ProgressError" and "ProgressMessage", you can define the error field in "ProgressInfo" directly.

@HusterWan

@HusterWan
Copy link
Contributor Author

@skoo87 Thanks for your opinion, i think all your points is reasonable, i will fix my code later

ctrd/image.go Outdated
@@ -160,7 +172,7 @@ outer:
}
// update status of active entries!
for _, active := range active {
progresses[active.Ref] = ProgressInfo{
progresses[active.Ref] = &ProgressInfo{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually I do not like this block. It is so long and so hard to understand without annotations. Maybe in a follow-up, we need to refactor this a little bit to make this more readable.

@pouchrobot pouchrobot added size/S and removed size/L labels Nov 27, 2017
@HusterWan
Copy link
Contributor Author

@skoo87 I made a new PR, please review the code, if there has any problem, just ping me any time, thanks.

cli/pull.go Outdated
@@ -79,11 +80,16 @@ func renderOutput(responseBody io.ReadCloser) {
fmt.Fprintf(os.Stderr, "failed to read the closing token: %v", err)
return
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the blank line is superfluous.

cli/pull.go Outdated
}

func display(w io.Writer, statuses []ctrd.ProgressInfo, start time.Time) {
var total int64
for _, status := range statuses {
if len(status.ErrorMessage) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

len(status.ErrorMessage) > 0 ===> status.ErrorMessage != ""

Using len(), We will think it's a slice array and so on.

ctrd/image.go Outdated
Code: http.StatusInternalServerError,
ErrorMessage: err.Error(),
}
msgList = append(msgList, errMsg)
Copy link
Contributor

Choose a reason for hiding this comment

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

s/msgList/messages/g , the variable name does not need to contain it's type.

Others, We can combine those codes into one line.
messages := []ProgressInfo{
{
Code: xxxx,
ErrorMessage: xxxx,
}
}

@skoowoo
Copy link
Contributor

skoowoo commented Nov 28, 2017

Please squash your commits into single one commit, thanks. @HusterWan

@HusterWan
Copy link
Contributor Author

Updated, Please take another look. @skoo87 Thanks

@skoowoo
Copy link
Contributor

skoowoo commented Nov 28, 2017

the "PR" is conflicting, please rebase it. @HusterWan

Signed-off-by: 万仔仁 <zirenwan@gmail.com>
@HusterWan
Copy link
Contributor Author

@skoo87 rebase done

@skoowoo
Copy link
Contributor

skoowoo commented Nov 28, 2017

LGTM

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Nov 28, 2017
@skoowoo skoowoo merged commit 4b3b79e into AliyunContainerService:master Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug This is bug report for project LGTM one maintainer or community participant agrees to merge the pull reuqest. size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Question about the images in pouch
4 participants