Skip to content

Return 413 HTTP status for S3 uploads if max upload limit is reached

Stan Hu requested to merge sh-return-413-for-s3-artifact-uploads into master

When an upload (e.g. a CI artifact) reaches the maximum file size limit, uploads via S3 would return a 500 error to the user. This made it difficult to understand why the upload failed.

This was happening because the hardLimitReader was aborting the transfer with ErrEntityTooLarge, but this error was wrapped in layers of AWS errors. Since none of these AWS errors were understood by the file handler, a 500 error was returned.

To fix this, AWS has a way to retrieve the original error. We now recursively go down the error stack to find the root cause.

Note that there is an open issue in the AWS SDK to make this easier with Golang (https://github.com/aws/aws-sdk-go/issues/2820).

This merge request would have saved me a lot of time because I didn't expect an Omnibus install would come with only a 100 MB limit: gitlab-runner#3524 (comment 447485983)

Edited by Stan Hu

Merge request reports