Backports https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/9840 to CE.
https://gitlab.com/gitlab-org/gitlab-ee/issues/9445