[PR #4056] [management] Stop using locking share for read calls to avoid deadlocks #22347

Open
opened 2026-08-05 06:05:51 -04:00 by saavagebueno · 0 comments
Owner

Original Pull Request: https://github.com/netbirdio/netbird/pull/4056

State: closed
Merged: No


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.

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • 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.

**Original Pull Request:** https://github.com/netbirdio/netbird/pull/4056 **State:** closed **Merged:** No --- ## 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 <!-- branch-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](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md).
saavagebueno added the pull-request label 2026-08-05 06:05:51 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#22347