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

Handle the 404 empty response when getting a single artifact file #561

Open
PMExtra opened this issue Nov 14, 2023 · 3 comments
Open

Handle the 404 empty response when getting a single artifact file #561

PMExtra opened this issue Nov 14, 2023 · 3 comments

Comments

@PMExtra
Copy link
Contributor

PMExtra commented Nov 14, 2023

https://docs.gitlab.com/ee/api/job_artifacts.html#download-a-single-artifact-file-by-job-id
https://docs.gitlab.com/ee/api/job_artifacts.html#download-a-single-artifact-file-from-specific-tag-or-branch

When downloading a single artifact file that does not exist, GitLab will return an empty 404 response with a zero-length body.

Maybe this behavior only appeared in 16.0+, I upgraded from 15.6 to 16.3 yesterday and then met this problem I've never seen before.

Anyway, we can reproduce it from gitlab.com, eg.

For the 404 empty response, NGitLab will throw a System.IO.IOException from GitLabRequest.HandleWebException at https://github.com/ubisoft/NGitLab/blob/6.42.2/NGitLab/Impl/HttpRequestor.GitLabRequest.cs#L133

Stacktrace:

System.IO.IOException: The response ended prematurely, with at least 2 additional bytes expected.
   at System.Net.Http.HttpConnection.ContentLengthReadStream.Read(Span`1 buffer)
   at System.IO.StreamReader.ReadBuffer()
   at System.IO.StreamReader.ReadToEnd()
   at NGitLab.Impl.HttpRequestor.GitLabRequest.HandleWebException(WebException ex) in /_/NGitLab/Impl/HttpRequestor.GitLabRequest.cs:line 133
   at NGitLab.Impl.HttpRequestor.GitLabRequest.GetResponseImpl(RequestOptions options) in /_/NGitLab/Impl/HttpRequestor.GitLabRequest.cs:line 106
   at NGitLab.Extensions.FunctionRetryExtensions.Retry[T](Func`1 action, Func`3 predicate, TimeSpan waitTime, Int32 maxRetryCount, Boolean useExponentialBackoff) in /_/NGitLab/Extensions/FunctionRetryExtensions.cs:line 41
   at NGitLab.Impl.HttpRequestor.Stream(String tailAPIUrl, Action`1 parser) in /_/NGitLab/Impl/HttpRequestor.cs:line 118
   at NGitLab.Impl.JobClient.GetJobArtifact(Int32 jobId, String path)
@PMExtra
Copy link
Contributor Author

PMExtra commented Nov 14, 2023

By the way, shall we always disable the retry policy for this case?
(It will only retry when getting responses with code >= 500 or timeout)

@PMExtra
Copy link
Contributor Author

PMExtra commented Nov 14, 2023

Sorry, it's a GitLab bug: https://gitlab.com/gitlab-org/gitlab/-/issues/414807

But it seems like it won't be fixed recently. Can we make some improvements for NGitLab to avoid it?

@meziantou
Copy link
Contributor

You can submit a PR to improve this behavior. Maybe a try/catch in https://github.com/ubisoft/NGitLab/blob/6.42.2/NGitLab/Impl/HttpRequestor.GitLabRequest.cs#L127 is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants