Ports https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/2115/ to 9.4, as discussed in https://gitlab.com/gitlab-org/gitlab-ce/issues/30420 / https://gitlab.slack.com/archives/C0XM5UU6B/p1501008448597926
/cc @mkozono