Skip to content

Draft: Resolve "Workhorse returns 200 when Get file archive api call fails"

What does this MR do and why?

This MR aims to fix the HTTP status code that's returned from the https://docs.gitlab.com/ee/api/repositories.html#get-file-archive API endpoint when there's an issue within Workhorse. Currently a HTTP 200 is always returned, regardless of success or error.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

It's a little hard to test, but the following should test this code:

  1. Apply the follow diff to force a HTTP 500:

    diff --git a/workhorse/internal/git/archive.go b/workhorse/internal/git/archive.go
    index bbf5d76c0e37..99a997e0fa4b 100644
    --- a/workhorse/internal/git/archive.go
    +++ b/workhorse/internal/git/archive.go
    @@ -64,7 +64,7 @@ func (a *archive) Inject(w http.ResponseWriter, r *http.Request, sendData string
    		return
    	}
    
    -	cacheEnabled := !params.DisableCache
    +	cacheEnabled := false
    	archiveFilename := path.Base(params.ArchivePath)
    
    	if cacheEnabled {
    @@ -115,7 +115,7 @@ func (a *archive) Inject(w http.ResponseWriter, r *http.Request, sendData string
    
    	// Start writing the response
    	setArchiveHeaders(w, format, archiveFilename)
    -	w.WriteHeader(http.StatusOK)
    +	w.WriteHeader(http.StatusInternalServerError)
    
    	if _, err := io.Copy(w, reader); err != nil {
    		w.WriteHeader(http.StatusInternalServerError)
  2. Recompile and restart workhorse - (cd <GDK_ROOT>/gitlab/workhorse && make && gdk restart workhorse)

  3. Perform an API request and observe the HTTP 500 - cd /tmp ; rm -f archive.tar.gz ; curl -v -H "PRIVATE-TOKEN: ${TOKEN}" --output archive.tar.gz "http://gdk.test:3000/api/v4/projects/7/repository/archive" ; ls -la archive.tar.gz

Related to #471955

Edited by Ash McKenzie

Merge request reports