From 51d950d3fb83762c3a517b11176769abddc0173a Mon Sep 17 00:00:00 2001 From: Karen Chen Date: Sun, 4 Aug 2024 23:05:12 -0400 Subject: [PATCH] add check for LockUntil field --- v2/lockrenewer.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/v2/lockrenewer.go b/v2/lockrenewer.go index 5abb542..1e53e7e 100644 --- a/v2/lockrenewer.go +++ b/v2/lockrenewer.go @@ -182,11 +182,11 @@ 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 := time.Until(*message.LockedUntil) // assumes messages.LockedUntil is set - if renewalTimeout < 0 { - // if the lock is already expired, we should not attempt to renew it. + if message.LockedUntil == nil || time.Until(*message.LockedUntil) < 0 { + // if the lock doesn't exist or is already expired, we should not attempt to renew it. return lockLostErr } + renewalTimeout := time.Until(*message.LockedUntil) if *plr.renewalTimeout > 0 { renewalTimeout = *plr.renewalTimeout }