Fix - make lease timeout range check more robust
MODIFY
src/WebJobs.Script/Host/PrimaryHostCoordinator.cs
src/WebJobs.Script/Host/PrimaryHostCoordinator.cs
@@ -89,9 +89,9 @@ internal IDistributedLock LockHandle
ILoggerFactory loggerFactory,
TimeSpan? renewalInterval = null)
{
- if (leaseTimeout.TotalSeconds < 15 || leaseTimeout.TotalSeconds > 60)
+ if (leaseTimeout < TimeSpan.FromSeconds(15) || leaseTimeout > TimeSpan.FromSeconds(60))
{
- throw new ArgumentOutOfRangeException(nameof(leaseTimeout), $"The {nameof(leaseTimeout)} should be between 15 and 60 seconds");
+ throw new ArgumentOutOfRangeException(nameof(leaseTimeout), $"The {nameof(leaseTimeout)} should be between 15 and 60 seconds but was '{leaseTimeout}'");
}
var manager = new PrimaryHostCoordinator(lockManager, leaseTimeout, hostId, instanceId, loggerFactory, renewalInterval);

MODIFY
test/WebJobs.Script.Tests.Integration/PrimaryHostCoordinatorTests.cs
test/WebJobs.Script.Tests.Integration/PrimaryHostCoordinatorTests.cs
@@ -37,6 +37,20 @@ private static IDistributedLockManager CreateLockManager()
return lockManager;
}
+ [Theory]
+ [InlineData(14.99)]
+ [InlineData(60.01)]
+ public void RejectsInvalidLeaseTimeout(double leaseTimeoutSeconds)
+ {
+ var leaseTimeout = TimeSpan.FromSeconds(leaseTimeoutSeconds);
+
+ string hostId = Guid.NewGuid().ToString();
+ string instanceId = Guid.NewGuid().ToString();
+
+ Assert.Throws<ArgumentOutOfRangeException>(
+ () => PrimaryHostCoordinator.Create(CreateLockManager(), leaseTimeout, hostId, instanceId, _loggerFactory));
+ }
+
[Fact]
public async Task HasLease_WhenLeaseIsAcquired_ReturnsTrue()
{

Fix #2363 - make lease timeout range check more robust