tq: avoid nil pointer dereference on unexpected failure

When we get an error making an API request, we check to see if the
response is a 429, and if so, we attempt to back off and retry later.
However, we failed to check if we actually had a response; if the
response was missing (say, because we had a network issue), then we
would dereference a nil pointer.

Instead, let's explicitly check for a non-nil response before querying
it for a status code.

Co-authored-by: Taylor Blau <me@ttaylorr.com>
This commit is contained in:
brian m. carlson 2019-02-19 15:11:24 +00:00
parent 3b3fa90b14
commit 4775f9c19c
No known key found for this signature in database
GPG Key ID: 2D0C9BC12F82B3A1

@ -123,6 +123,12 @@ func (a *basicUploadAdapter) DoTransfer(ctx interface{}, t *Transfer, cb Progres
err = errors.Wrap(err, perr.Error())
}
if res == nil {
// We encountered a network or similar error which caused us
// to not receive a response at all.
return errors.NewRetriableError(err)
}
if res.StatusCode == 429 {
retLaterErr := errors.NewRetriableLaterError(err, res.Header["Retry-After"][0])
if retLaterErr != nil {