diff --git a/src/WebJobs.Extensions.CosmosDB/Trigger/CosmosDBTargetScaler.cs b/src/WebJobs.Extensions.CosmosDB/Trigger/CosmosDBTargetScaler.cs index 6b3f56cc..1432d1d3 100644 --- a/src/WebJobs.Extensions.CosmosDB/Trigger/CosmosDBTargetScaler.cs +++ b/src/WebJobs.Extensions.CosmosDB/Trigger/CosmosDBTargetScaler.cs @@ -57,7 +57,19 @@ internal TargetScalerResult GetScaleResultInternal(TargetScalerContext context, concurrency = DefaultMaxItemsPerInvocation; } - int targetWorkerCount = (int)Math.Ceiling(remainingWork / (decimal)concurrency); + int targetWorkerCount; + + try + { + checked + { + targetWorkerCount = (int)Math.Ceiling(remainingWork / (decimal)concurrency); + } + } + catch (OverflowException) + { + targetWorkerCount = int.MaxValue; + } string targetScaleMessage = $"Target worker count for function '{_functionId}' is '{targetWorkerCount}' (MonitoredContainerId='{_monitoredContainer.Id}', MonitoredContainerDatabaseId='{_monitoredContainer.Database.Id}', RemainingWork ='{remainingWork}', Concurrency='{concurrency}')."; diff --git a/test/WebJobs.Extensions.CosmosDB.Tests/Trigger/CosmosDBTargetScalerTests.cs b/test/WebJobs.Extensions.CosmosDB.Tests/Trigger/CosmosDBTargetScalerTests.cs index 8ca69b2e..626e458d 100644 --- a/test/WebJobs.Extensions.CosmosDB.Tests/Trigger/CosmosDBTargetScalerTests.cs +++ b/test/WebJobs.Extensions.CosmosDB.Tests/Trigger/CosmosDBTargetScalerTests.cs @@ -71,6 +71,9 @@ public CosmosDBTargetScalerTests() [InlineData(null, 0, 3, 0)] [InlineData(50, 200, 0, 4)] [InlineData(-50, 200, 0, 2)] + [InlineData(1, 2147483650, 1, 1)] + [InlineData(1, 2147483650, 2147483647, 2147483647)] + [InlineData(2, 2147483650, 1073741825, 1073741825)] public void GetScaleResultInternal(int? concurrency, long remainingWork, int partitionCount, int expectedTargetWorkerCount) { TargetScalerContext targetScalerContext = new TargetScalerContext