修复凭据恢复取消等待
让凭据根目录读取遵循调用上下文,避免恢复码生成在凭据锁竞争时绕过取消信号并长时间阻塞。
This commit is contained in:
parent
cff5d489ca
commit
2f83a22dd2
@ -54,12 +54,19 @@ func (s *Service) SetVaultRoot(root string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) VaultRoot() string {
|
func (s *Service) VaultRoot() string {
|
||||||
|
root, _ := s.VaultRootContext(context.Background())
|
||||||
|
return root
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) VaultRootContext(ctx context.Context) (string, error) {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
return ""
|
return "", ErrUnavailable
|
||||||
|
}
|
||||||
|
if err := s.mu.LockContext(ctx); err != nil {
|
||||||
|
return "", err
|
||||||
}
|
}
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
return s.vaultRoot
|
return s.vaultRoot, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(engine *xorm.Engine) (*Service, error) {
|
func NewService(engine *xorm.Engine) (*Service, error) {
|
||||||
@ -180,7 +187,10 @@ func (s *Service) generateRecoveryCodes(ctx context.Context, userID int, count i
|
|||||||
}()
|
}()
|
||||||
codes = make([]string, 0, count)
|
codes = make([]string, 0, count)
|
||||||
items := make([]models.RecoveryCode, 0, count)
|
items := make([]models.RecoveryCode, 0, count)
|
||||||
vaultRoot := s.VaultRoot()
|
vaultRoot, err := s.VaultRootContext(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user