mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 07:16:38 +00:00
[management] fix pg db deadlock after app panic (#4772)
This commit is contained in:
@@ -2914,6 +2914,23 @@ func (s *SqlStore) ExecuteInTransaction(ctx context.Context, operation func(stor
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
|
||||
if s.storeEngine == types.PostgresStoreEngine {
|
||||
if err := tx.Exec("SET LOCAL statement_timeout = '1min'").Error; err != nil {
|
||||
tx.Rollback()
|
||||
return fmt.Errorf("failed to set statement timeout: %w", err)
|
||||
}
|
||||
if err := tx.Exec("SET LOCAL lock_timeout = '1min'").Error; err != nil {
|
||||
tx.Rollback()
|
||||
return fmt.Errorf("failed to set lock timeout: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// For MySQL, disable FK checks within this transaction to avoid deadlocks
|
||||
// This is session-scoped and doesn't require SUPER privileges
|
||||
|
||||
Reference in New Issue
Block a user