Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions management/internals/shared/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ func (s *Server) Sync(req *proto.EncryptedMessage, srv proto.ManagementService_S
// nolint:staticcheck
ctx = context.WithValue(ctx, nbContext.AccountIDKey, accountID)

defer func() {
log.WithContext(ctx).Debugf("Sync took %s", time.Since(reqStart))
}()

start := time.Now()
unlock := s.acquirePeerLockByUID(ctx, peerKey.String())
defer func() {
Expand Down Expand Up @@ -565,6 +569,7 @@ func (s *Server) Login(ctx context.Context, req *proto.EncryptedMessage) (*proto
if s.appMetrics != nil {
s.appMetrics.GRPCMetrics().CountLoginRequestDuration(time.Since(reqStart), accountID)
}
log.WithContext(ctx).Debugf("Login took %s", time.Since(reqStart))
}()

if loginReq.GetMeta() == nil {
Expand Down
6 changes: 5 additions & 1 deletion management/server/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func (am *DefaultAccountManager) DeleteGroups(ctx context.Context, accountID, us

err = am.Store.ExecuteInTransaction(ctx, func(transaction store.Store) error {
for _, groupID := range groupIDs {
group, err := transaction.GetGroupByID(ctx, store.LockingStrengthUpdate, accountID, groupID)
group, err := transaction.GetGroupByID(ctx, store.LockingStrengthNone, accountID, groupID)
if err != nil {
allErrors = errors.Join(allErrors, err)
continue
Expand All @@ -442,6 +442,10 @@ func (am *DefaultAccountManager) DeleteGroups(ctx context.Context, accountID, us
deletedGroups = append(deletedGroups, group)
}

if len(groupIDsToDelete) == 0 {
return allErrors
}

if err = transaction.DeleteGroups(ctx, accountID, groupIDsToDelete); err != nil {
return err
}
Expand Down
17 changes: 15 additions & 2 deletions management/server/store/sql_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"github.com/netbirdio/netbird/management/server/util"
"github.com/netbirdio/netbird/route"
"github.com/netbirdio/netbird/shared/management/status"
"github.com/netbirdio/netbird/shared/sshauth"

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Management / Integration (amd64, sqlite)

"github.com/netbirdio/netbird/shared/sshauth" imported and not used

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Management / Benchmark (API) (amd64, postgres)

"github.com/netbirdio/netbird/shared/sshauth" imported and not used

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Management / Integration (amd64, postgres)

"github.com/netbirdio/netbird/shared/sshauth" imported and not used

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Management / Benchmark (API) (amd64, sqlite)

"github.com/netbirdio/netbird/shared/sshauth" imported and not used

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Management / Unit (amd64, sqlite)

"github.com/netbirdio/netbird/shared/sshauth" imported and not used

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Management / Benchmark (amd64, postgres)

"github.com/netbirdio/netbird/shared/sshauth" imported and not used

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Management / Unit (amd64, postgres)

"github.com/netbirdio/netbird/shared/sshauth" imported and not used

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Management / Benchmark (amd64, sqlite)

"github.com/netbirdio/netbird/shared/sshauth" imported and not used

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Management / Unit (amd64, mysql)

"github.com/netbirdio/netbird/shared/sshauth" imported and not used

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Linux

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Linux

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Linux

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Linux

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Linux

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / JS / Lint

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / JS / Lint

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / JS / Lint

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / JS / Lint

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / JS / Lint

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Client / Unit

"github.com/netbirdio/netbird/shared/sshauth" imported and not used

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Darwin

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Darwin

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Darwin

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Darwin

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Darwin

"github.com/netbirdio/netbird/shared/sshauth" imported and not used) (typecheck)

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Client / Unit (amd64)

"github.com/netbirdio/netbird/shared/sshauth" imported and not used

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Client (Docker) / Unit

"github.com/netbirdio/netbird/shared/sshauth" imported and not used

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Client / Unit (386)

"github.com/netbirdio/netbird/shared/sshauth" imported and not used

Check failure on line 40 in management/server/store/sql_store.go

View workflow job for this annotation

GitHub Actions / Client / Unit

"github.com/netbirdio/netbird/shared/sshauth" imported and not used
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
)

const (
Expand Down Expand Up @@ -2897,8 +2898,11 @@
}

func (s *SqlStore) ExecuteInTransaction(ctx context.Context, operation func(store Store) error) error {
timeoutCtx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
Comment thread
mlsmaycon marked this conversation as resolved.
Outdated

startTime := time.Now()
tx := s.db.Begin()
tx := s.db.WithContext(timeoutCtx).Begin()
if tx.Error != nil {
return tx.Error
}
Expand Down Expand Up @@ -2933,6 +2937,9 @@
err := operation(repo)
if err != nil {
tx.Rollback()
if errors.Is(err, context.DeadlineExceeded) || errors.Is(timeoutCtx.Err(), context.DeadlineExceeded) {
log.WithContext(ctx).Warnf("transaction exceeded 5 minute timeout after %v, stack: %s", time.Since(startTime), debug.Stack())
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return err
}

Expand All @@ -2945,13 +2952,19 @@
}

err = tx.Commit().Error
if err != nil {
if errors.Is(err, context.DeadlineExceeded) || errors.Is(timeoutCtx.Err(), context.DeadlineExceeded) {
log.WithContext(ctx).Warnf("transaction commit exceeded 5 minute timeout after %v, stack: %s", time.Since(startTime), debug.Stack())
}
return err
}

log.WithContext(ctx).Tracef("transaction took %v", time.Since(startTime))
if s.metrics != nil {
s.metrics.StoreMetrics().CountTransactionDuration(time.Since(startTime))
}

return err
return nil
}

func (s *SqlStore) withTx(tx *gorm.DB) Store {
Expand Down
Loading