Skip to content

workhorse: Downgrade incomplete multipart uploads to 400 errors

Stan Hu requested to merge sh-fix-invalid-multipart-status-code into master

What does this MR do and why?

In gitlab-com/gl-infra/production#17587 (closed), our 500 error rates rose when incomplete multipart uploads were sent, but this is really a client error, not a server error. This commit downgrades that to a 400 error by doing an ugly string comparison in multipart.NextPart to check for this condition.

How to set up and validate locally

Happy path

  1. Check out this branch.
  2. Compile workhorse by running make -C workhorse from the gitlab directory.
  3. gdk restart gitlab-workhorse
  4. Go to /-/user_settings/profile
  5. Update profile photo

Error path

  1. Open your browser's Inspect to see the POST request.
  2. Download the request data. It should something like:
-----------------------------16627824944090109022046164902
Content-Disposition: form-data; name="_method"

put
-----------------------------16627824944090109022046164902
Content-Disposition: form-data; name="authenticity_token"

SOME-TOKEN-HERE
-----------------------------16627824944090109022046164902
Content-Disposition: form-data; name="user[avatar]-trigger"; filename=""
Content-Type: application/octet-stream
  1. Save this request data to /tmp/test.txt.
  2. Truncate the last character or two from the file.
  3. Issue the curl request using the same Content-Type header from the request:
curl -v -X POST -H "Content-Type: multipart/form-data; boundary=---------------------------16627824944090109022046164902" https://gdk.test:3000/-/user_settings/profile -d @/tmp/test.txt
  1. This should return 400 Bad Request instead of 500 Internal Server Error.
Edited by Stan Hu

Merge request reports