Commit f1b857a5 authored by Stan Hu's avatar Stan Hu

Properly handle 503 errors in info/refs endpoint

Conflicting `render_503` implementations, one in `ApplicationController`
and another in `GitHttpController`, caused a "wrong number of arguments"
error.  To disambiguate these, rename the handler in `GitHttpController`
to `render_503_with_exception`.

Closes https://gitlab.com/gitlab-org/gitlab/issues/32925
parent b6c3cd13
......@@ -6,10 +6,10 @@ class Projects::GitHttpController < Projects::GitHttpClientController
before_action :access_check
prepend_before_action :deny_head_requests, only: [:info_refs]
rescue_from Gitlab::GitAccess::UnauthorizedError, with: :render_403
rescue_from Gitlab::GitAccess::NotFoundError, with: :render_404
rescue_from Gitlab::GitAccess::ProjectCreationError, with: :render_422
rescue_from Gitlab::GitAccess::TimeoutError, with: :render_503
rescue_from Gitlab::GitAccess::UnauthorizedError, with: :render_403_with_exception
rescue_from Gitlab::GitAccess::NotFoundError, with: :render_404_with_exception
rescue_from Gitlab::GitAccess::ProjectCreationError, with: :render_422_with_exception
rescue_from Gitlab::GitAccess::TimeoutError, with: :render_503_with_exception
# GET /foo/bar.git/info/refs?service=git-upload-pack (git pull)
# GET /foo/bar.git/info/refs?service=git-receive-pack (git push)
......@@ -58,19 +58,19 @@ class Projects::GitHttpController < Projects::GitHttpClientController
render json: Gitlab::Workhorse.git_http_ok(repository, repo_type, user, action_name)
end
def render_403(exception)
def render_403_with_exception(exception)
render plain: exception.message, status: :forbidden
end
def render_404(exception)
def render_404_with_exception(exception)
render plain: exception.message, status: :not_found
end
def render_422(exception)
def render_422_with_exception(exception)
render plain: exception.message, status: :unprocessable_entity
end
def render_503(exception)
def render_503_with_exception(exception)
render plain: exception.message, status: :service_unavailable
end
......
......@@ -22,5 +22,30 @@ describe Projects::GitHttpController do
expect(response.status).to eq(401)
end
context 'with exceptions' do
let(:project) { create(:project, :public, :repository) }
before do
allow(controller).to receive(:verify_workhorse_api!).and_return(true)
end
it 'returns 503 with GRPC Unavailable' do
allow(controller).to receive(:access_check).and_raise(GRPC::Unavailable)
get :info_refs, params: { service: 'git-upload-pack', namespace_id: project.namespace.to_param, project_id: project.path + '.git' }
expect(response.status).to eq(503)
end
it 'returns 503 with timeout error' do
allow(controller).to receive(:access_check).and_raise(Gitlab::GitAccess::TimeoutError)
get :info_refs, params: { service: 'git-upload-pack', namespace_id: project.namespace.to_param, project_id: project.path + '.git' }
expect(response.status).to eq(503)
expect(response.body).to eq 'Gitlab::GitAccess::TimeoutError'
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment