修复凭据恢复取消等待
Some checks are pending
Security Checks / security (push) Waiting to run

让凭据根目录读取遵循调用上下文,避免恢复码生成在凭据锁竞争时绕过取消信号并长时间阻塞。
This commit is contained in:
smail 2026-09-30 05:08:44 +08:00
parent 3924d0c33f
commit 25d3796bae

View File

@ -54,12 +54,19 @@ func (s *Service) SetVaultRoot(root 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 {
return ""
return "", ErrUnavailable
}
if err := s.mu.LockContext(ctx); err != nil {
return "", err
}
s.mu.Lock()
defer s.mu.Unlock()
return s.vaultRoot
return s.vaultRoot, nil
}
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)
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++ {
if err := ctx.Err(); err != nil {
return nil, err