[go: up one dir, main page]

Skip to content

Inconsistent state for Repository#branch_count and Repository#branch_names

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

@northrup moved a project from gitlab-cog/gitlab to gitlab-cog/gitlab-admin and found that the repository appeared empty on the Web UI.

When we looked at the state of the project cache, we saw this:

irb(main):057:0> proj.repository.branch_count
=> 0
irb(main):058:0> proj.repository.branch_names
=> ["master", "pc-try-without-tty", "refactor-runners", "refactor-runners-info", "templates-for-gitlab", "test"]

This is clearly an inconsistent state. Because branch_count is 0, Repository#has_visible_content? returned false and showed an empty repo. Pushing to a new branch fixed the issue.

How did this happen? My guess is that when the project was moved, the cache was flushed. However, before the move was done, something checked Repository#has_visible_content?, and since the repository was no longer there, the value got incorrectly set to 0.

It seems to me we may want to do something as the following:

  1. Don't cache the branch_count if it is 0; or if there is an error with Rugged, don't cache at all
  2. Check if the branch_count and branch_names.count is consistent. If it is not, flag an error and expire something.

@DouweM @yorickpeterse Thoughts?

Edited by 🤖 GitLab Bot 🤖