@@ -525,28 +525,30 @@ private async Task RenewLeasesAsync(SqlConnection connection, CancellationToken
525
525
{
526
526
try
527
527
{
528
- using ( SqlCommand renewLeasesCommand = this . BuildRenewLeasesCommand ( connection , transaction ) )
528
+ SqlCommand renewLeasesCommand = this . BuildRenewLeasesCommand ( connection , transaction ) ;
529
+ if ( renewLeasesCommand != null )
529
530
{
530
- var stopwatch = Stopwatch . StartNew ( ) ;
531
+ using ( renewLeasesCommand )
532
+ {
533
+ var stopwatch = Stopwatch . StartNew ( ) ;
531
534
532
- int rowsAffected = await renewLeasesCommand . ExecuteNonQueryAsyncWithLogging ( this . _logger , token , true ) ;
535
+ int rowsAffected = await renewLeasesCommand . ExecuteNonQueryAsyncWithLogging ( this . _logger , token , true ) ;
533
536
534
- long durationMs = stopwatch . ElapsedMilliseconds ;
537
+ long durationMs = stopwatch . ElapsedMilliseconds ;
535
538
536
- if ( rowsAffected > 0 )
537
- {
538
- this . _logger . LogDebug ( $ "Renewed leases for { rowsAffected } rows") ;
539
- // Only send an event if we actually updated rows to reduce the overall number of events we send
540
- var measures = new Dictionary < TelemetryMeasureName , double >
539
+ if ( rowsAffected > 0 )
541
540
{
542
- [ TelemetryMeasureName . DurationMs ] = durationMs ,
543
- } ;
544
-
545
- TelemetryInstance . TrackEvent ( TelemetryEventName . RenewLeases , this . _telemetryProps , measures ) ;
541
+ this . _logger . LogDebug ( $ "Renewed leases for { rowsAffected } rows") ;
542
+ // Only send an event if we actually updated rows to reduce the overall number of events we send
543
+ var measures = new Dictionary < TelemetryMeasureName , double >
544
+ {
545
+ [ TelemetryMeasureName . DurationMs ] = durationMs ,
546
+ } ;
547
+
548
+ TelemetryInstance . TrackEvent ( TelemetryEventName . RenewLeases , this . _telemetryProps , measures ) ;
549
+ }
550
+ transaction . Commit ( ) ;
546
551
}
547
-
548
-
549
- transaction . Commit ( ) ;
550
552
}
551
553
}
552
554
catch ( Exception e )
@@ -978,9 +980,12 @@ WHEN NOT MATCHED THEN
978
980
private SqlCommand BuildRenewLeasesCommand ( SqlConnection connection , SqlTransaction transaction )
979
981
{
980
982
string matchCondition = string . Join ( " OR " , this . _rowMatchConditions . Take ( this . _rowsToProcess . Count ) ) ;
983
+ // If the matchCondition is empty return null to avoid empty where clause query failure.
981
984
if ( string . IsNullOrEmpty ( matchCondition ) )
982
985
{
983
986
this . _logger . LogError ( $ "MatchCondition resolved to empty with '{ this . _rowsToProcess . Count } ' rowsToProcess.") ;
987
+ TelemetryInstance . TrackEvent ( TelemetryEventName . BuildRenewLeasesWithEmptyMatchCondtion ) ;
988
+ return null ;
984
989
}
985
990
string renewLeasesQuery = $@ "
986
991
{ AppLockStatements }
0 commit comments