mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-01 15:41:18 +00:00
fix(subscriptions): lock negative redemption updates
This commit is contained in:
1 parent
1c0a69c0ce
commit
85ed17b313
3 files changed
+169
No files matched your search
@@ -702,6 +702,14 @@ func (s *RedeemService) reduceOrCancelSubscription(ctx context.Context, userID,
|
||||
return ErrSubscriptionNotFound
|
||||
}
|
||||
|
||||
// Redemption already owns a transaction. Lock and reread the subscription
|
||||
// before computing changes: the redeem-code lock cannot serialize different
|
||||
// codes (or an administrator renewal) targeting the same subscription.
|
||||
sub, err = s.subscriptionService.userSubRepo.GetByIDForUpdate(ctx, sub.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("lock subscription for reduction: %w", err)
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
remaining := int(sub.ExpiresAt.Sub(now).Hours() / 24)
|
||||
if remaining < 0 {
|
||||
|
||||
Reference in new issue
Block a user