netbird icon indicating copy to clipboard operation
netbird copied to clipboard

[management] Stop using locking share for read calls to avoid deadlocks

Open mlsmaycon opened this issue 4 months ago • 1 comments

Describe your changes

This PR removes shared locking on read operations to avoid deadlocks and adds a GORM index on the UserID field in the Peer model.

  • Swapped all store.LockingStrengthShare usages for store.LockingStrengthNone on read calls.
  • Added a GORM index tag to Peer.UserID for improved lookup performance.

We've seen a few deadlock reports for queries with and without transactions that only needed to read data. This Pr removes the locking for share usage and left only the locking for update in use.

Issue ticket number and link

Stack

Checklist

  • [x] Is it a bug fix
  • [ ] Is a typo/documentation fix
  • [x] Is a feature enhancement
  • [ ] It is a refactor
  • [ ] Created tests that fail without the change (if possible)
  • [ ] Extended the README / documentation, if necessary

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

mlsmaycon avatar Jun 26 '25 10:06 mlsmaycon