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

Fix hard-coded timeout and error panic in API archive download endpoint (#20925) #21051

Merged
merged 6 commits into from
Sep 6, 2022

Commits on Sep 4, 2022

  1. fix hard-coded timeout and error panic in API archive download endpoi…

    …nt (go-gitea#20925)
    
    Backport go-gitea#20925
    
    This commit updates the `GET /api/v1/repos/{owner}/{repo}/archive/{archive}`
    endpoint which prior to this PR had a couple of issues.
    
    1. The endpoint had a hard-coded 20s timeout for the archiver to complete after
       which a 500 (Internal Server Error) was returned to client. For a scripted
       API client there was no clear way of telling that the operation timed out and
       that it should retry.
    
    2. Whenever the timeout _did occur_, the code used to panic. This was caused by
       the API endpoint "delegating" to the same call path as the web, which uses a
       slightly different way of reporting errors (HTML rather than JSON for
       example).
    
       More specifically, `api/v1/repo/file.go#GetArchive` just called through to
       `web/repo/repo.go#Download`, which expects the `Context` to have a `Render`
       field set, but which is `nil` for API calls. Hence, a `nil` pointer error.
    
    The code addresses (1) by dropping the hard-coded timeout. Instead, any
    timeout/cancelation on the incoming `Context` is used.
    
    The code addresses (2) by updating the API endpoint to use a separate call path
    for the API-triggered archive download. This avoids producing HTML-errors on
    errors (it now produces JSON errors).
    
    Signed-off-by: Peter Gardfjäll <peter.gardfjall.work@gmail.com>
    petergardfjall authored and zeripath committed Sep 4, 2022
    Configuration menu
    Copy the full SHA
    3dfb20d View commit details
    Browse the repository at this point in the history
  2. partial backport from go-gitea#20903

    Signed-off-by: Andrew Thornton <art27@cantab.net>
    zeripath committed Sep 4, 2022
    Configuration menu
    Copy the full SHA
    33c1744 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    591ba3f View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    8e07f60 View commit details
    Browse the repository at this point in the history

Commits on Sep 5, 2022

  1. Fix lint

    lunny committed Sep 5, 2022
    Configuration menu
    Copy the full SHA
    5b4cfcf View commit details
    Browse the repository at this point in the history

Commits on Sep 6, 2022

  1. Configuration menu
    Copy the full SHA
    6831c66 View commit details
    Browse the repository at this point in the history