Skip to content

Fix error 500 loading branch with UTF-8 characters with performance bar

Stan Hu requested to merge sh-fix-protected-branch-utf8 into master

What does this MR do and why?

When we added caching for protected branch names in !64738 (merged), we did not account for UTF-8 characters being used in the branch name.

The cache key would be encoded in ASCII-8BIT due to the branch name coming from Gitaly, but when the performance bar were enabled the Redis activity would be dumped to JSON. Since this string wasn't UTF-8, Ruby would throw up a Encoding::UndefinedConversionError.

This commit fixes the problem by hashing the ref name with SHA-1 to avoid needing to deal with any encoding issues.

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/343698

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Enable the performance bar.
  2. Create a branch “jmd-add-tests-branch-vs-tags-issues”.
  3. With previous code, you would see a 500 error.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Stan Hu

Merge request reports