Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
karenychen committed Aug 4, 2024
1 parent 7e80924 commit ca3a330
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions v2/lockrenewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (plr *peekLockRenewer) startPeriodicRenewal(ctx context.Context, message *a

func (plr *peekLockRenewer) renewMessageLock(ctx context.Context, message *azservicebus.ReceivedMessage, options *azservicebus.RenewMessageLockOptions) error {
lockLostErr := &azservicebus.Error{Code: azservicebus.CodeLockLost}
renewalTimeout := message.LockedUntil.Sub(time.Now())
renewalTimeout := time.Until(*message.LockedUntil)
if renewalTimeout < 0 {
// if the lock is already expired, we should not attempt to renew it.
return lockLostErr
Expand All @@ -191,9 +191,9 @@ func (plr *peekLockRenewer) renewMessageLock(ctx context.Context, message *azser
renewalTimeout = *plr.renewalTimeout
}
// we should keep retrying until lock expiry or until message context is done
for message.LockedUntil.Sub(time.Now()) > 0 && ctx.Err() == nil {
for time.Until(*message.LockedUntil) > 0 && ctx.Err() == nil {
err := plr.renewMessageLockWithTimeout(ctx, renewalTimeout, message, options)
// exit the renewal if we get any error other than context canceled.
// exit the renewal if we get any error other than context canceled or if the error is nil.
if !errors.Is(err, context.Canceled) {
return err
}
Expand All @@ -209,5 +209,5 @@ func (plr *peekLockRenewer) renewMessageLockWithTimeout(ctx context.Context, tim
getLogger(ctx).Info(fmt.Sprintf("renewing lock with timeout: %s", timeout))
renewalCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
return plr.renewMessageLock(renewalCtx, message, options)
return plr.lockRenewer.RenewMessageLock(renewalCtx, message, options)
}

0 comments on commit ca3a330

Please sign in to comment.