Skip to content
Snippets Groups Projects

Fix two data races in the branch names cache

Merged Nick Thomas requested to merge repository-set-cache-races into master
All threads resolved!

What does this MR do?

Expiry of the branch name cache could race with checking inclusion, in such a way that a branch may be marked as non-existent when it does in fact exist.

This MR uses Redis transactions to atomically take the existence of the set at the same time as the smembers / sismembers call, so we can distinguish between "an empty value exists in the cache" and "the cache is empty".

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #326066 (closed)

Edited by Nick Thomas

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Nick Thomas
  • Nick Thomas
  • Nick Thomas added 1 commit

    added 1 commit

    • 5aa5f3f4 - Fix two data races in the branch names cache

    Compare with previous version

  • Author Contributor

    As ever, it's a pain to write specs that exercise the race condition precisely :grimacing:.

    The use of redis.multi in the fix for both races is a simple fix; it relies on redis's transactional behaviour to make the "check-then-use" idiom safe: https://redis.io/topics/transactions

    The most important part on that page is:

    It can never happen that a request issued by another client is served in the middle of the execution of a Redis transaction

  • Author Contributor

    @digitalmoksha do you mind acting as reviewer for this MR? I think you're involved with #326066 (closed) from AMER :sweat_smile: . I'm just finishing up for the day, the changed specs did pass locally though :fingers_crossed: .

    These are just theoretical races at the moment - I've not seen evidence that they're the cause of the problems we're seeing. Still, I think they're worth fixing, and if that evidence does come along we can look at turning it into a hotfix.

  • Nick Thomas requested review from @digitalmoksha

    requested review from @digitalmoksha

  • Not really involved, but happy to take a look

  • Nick Thomas
  • Brett Walker requested review from @stanhu

    requested review from @stanhu

  • Nick Thomas added 1 commit

    added 1 commit

    • fafb29e2 - Fix two data races in the branch names cache

    Compare with previous version

  • Stan Hu resolved all threads

    resolved all threads

  • Stan Hu approved this merge request

    approved this merge request

  • merged

  • Stan Hu mentioned in commit 982571d2

    mentioned in commit 982571d2

  • added workflowproduction label and removed workflowstaging label

  • mentioned in issue #273131 (closed)

  • Please register or sign in to reply
    Loading