Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
store: handle EOF via url.Error check #3126
Conversation
mvo5
approved these changes
Apr 3, 2017
Looks good, thanks for tracking this done! Some small suggestions inside but no blockers.
| + mockServer.CloseClientConnections() | ||
| + return | ||
| + } | ||
| + jsonReq, err := ioutil.ReadAll(r.Body) |
mvo5
Apr 3, 2017
Collaborator
You could write this slightly shorter by using a json.Decoder, something like:
var resp struct {
Snaps []map[string]interface{} `json:"snaps"`
Fields []string `json:"fields"`
}
err := json.NewDecoder(r.Body).Decode(&resp)
c.Assert(err, IsNil)
| + c.Assert(mockServer, NotNil) | ||
| + defer mockServer.Close() | ||
| + | ||
| + var err error |
stolowski
Apr 3, 2017
Contributor
I've simplified it a bit, there is no need to examine all that in detail indeed (we have other tests that do that), but I think a sanity test that ensure the client sends seinsible data on retry is useful (this gives us confidence that subsequent requests have proper body after initial failure). Let me know if that is what you meant here?
zyga
Apr 4, 2017
Contributor
I think what mvo meant is that you don't need to define it as the subsequent line does it for you.
stolowski
added some commits
Apr 3, 2017
zyga
and others
added some commits
Apr 4, 2017
niemeyer
approved these changes
Apr 4, 2017
LGTM, but let's please tweak the logic just slightly:
| @@ -70,6 +71,9 @@ func shouldRetryError(attempt *retry.Attempt, err error) bool { | ||
| if !attempt.More() { | ||
| return false | ||
| } | ||
| + if urlErr, ok := err.(*url.Error); ok { | ||
| + return urlErr.Err == io.ErrUnexpectedEOF || urlErr.Err == io.EOF |
niemeyer
Apr 4, 2017
Contributor
Instead of repeating the check here, it'd be better to just unwrap and let the follow up code run
if urlErr, ok := err.(*url.Error); ok {
err = urlErr
}
stolowski
Apr 4, 2017
Contributor
Good idea, done, althouth it needs to be urlErr.Err, and also the follow up condition on netErr needs "else if", otherwise the re-assigned err falls into it and into Timeout() check.
stolowski
added some commits
Apr 4, 2017
|
@stolowski Thanks for addressing gustavos point! |
stolowski commentedApr 3, 2017
Handle EOF errors such as "Post http://127.0.0.1:36904/updates/: EOF" by introspection via url.Error. Added test cases for EOF.