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

Feat: Don't retry function upload on 400 or 422 status #478

Merged
merged 21 commits into from
Sep 22, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions go/porcelain/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,17 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl
context.GetLogger(ctx).WithError(operationError).Errorf("Failed to upload file %v", f.Name)
apiErr, ok := operationError.(apierrors.Error)

if ok && apiErr.Code() == 401 {
sharedErr.mutex.Lock()
sharedErr.err = operationError
sharedErr.mutex.Unlock()
if ok {
if apiErr.Code() == 401 {
sharedErr.mutex.Lock()
sharedErr.err = operationError
sharedErr.mutex.Unlock()
}

// TODO this changes retry behaviour for the fileUpload case as well. OK?
if apiErr.Code()/100 == 4 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would voice the same concern as @biruwon pointed out here. I'm concerned that retrying all the 4xx calls might be a stretch? (i.e. should we retry 429's too?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Updated to just skip the retry for 400 and 422 status codes 🙂

return nil
JGAntunes marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

So I had to spend some time looking through this but I believe there's some room for improvement here (in the retry strategy I mean 😅)

I was initially going to say that we didn't want to return nil here but then I got that the idea is to actually exit the retry early. We have a check at the beggining of the retry method where we error out if sharedErr is set:

  • if sharedErr.err != nil {
    sharedErr.mutex.Unlock()
    return fmt.Errorf("aborting upload of file %s due to failed upload of another file", f.Name)
    }

However this case is also unideal because it just means we'll keep on retrying and erroring out here until we exhaust the count.

I was reading through the docs for backoff - https://pkg.go.dev/github.com/cenkalti/backoff/v4#Retry - and it seems like they have support for a PermanentError - https://pkg.go.dev/github.com/cenkalti/backoff/v4#PermanentError - which is a way for us to exit out of the retry loop while keeping the "error semantics" correct. It seems like this would be the perfect fit for this case? What do you think?

}
}
}

Expand Down
Loading