Azure / Azure/azure-functions-host

Expose `PrimaryHostCoordinator` lease timeout and renewal interval as optional host configuration

Open
#11,930 0 comments 0 reactions 0 assignees View on GitHub
Needs: Triage (Functions)
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 10h
Merged PRs (30d)
36

Description

## Summary

Azure Functions enables `PrimaryHostCoordinator` and maintains a Blob lease at:

`azure-webjobs-hosts/locks//host`

The current behavior is effectively:

- `LeaseTimeout = 15 seconds`
- `RenewalInterval = 12 seconds`

For a continuously active Function App, this produces one `RenewBlobLease` approximately every 12 seconds.

I propose exposing `PrimaryHostCoordinatorOptions.LeaseTimeout` and `PrimaryHostCoordinatorOptions.RenewalInterval` as **optional customer configuration**, while preserving the existing defaults unless explicitly overridden.

## Evidence

On a Flex Consumption Function App using managed identity/OAuth for `AzureWebJobsStorage`, Storage diagnostics show:

```text
OperationName: RenewBlobLease
URI: https://.blob.core.windows.net/azure-webjobs-hosts/locks//host?comp=lease
AuthenticationType: OAuth
UserAgent: azsdk-net-Storage.Blobs/12.22.1
Status: 200 Success
```

Measured cadence:

```text
~1 renewal / 12 seconds
~5 / minute
~300 / hour
~7,200 / day
~223,200 / 31-day month
```

This is from a single continuously active host, not scale-out multiplication.

In my account, these renewals are the dominant contributor by count to the Blob Storage `All Other Operations` meter and cost roughly €0.11–€0.12/month for one continuously active Function App. The amount is small per app, but it is fixed background overhead and scales with the number of continuously active apps.

## Existing runtime support

`PrimaryHostCoordinatorOptions` already exposes:

```csharp
public TimeSpan LeaseTimeout { get; set; }
public TimeSpan? RenewalInterval { get; set; }
```

with `LeaseTimeout` constrained to 15–60 seconds.

`PrimaryHostCoordinator` uses:

```csharp
RenewalInterval ?? LeaseTimeout.Add(TimeSpan.FromSeconds(-3))
```

So the runtime already supports configurations such as:

```text
LeaseTimeout = 60 seconds
RenewalInterval = 30 seconds
```

The missing piece is a supported Azure Functions configuration binding.

The existing `host.json` `singleton` settings do not apply here; they configure `SingletonOptions`, not the Primary Host Coordinator `/host` lease.

## Proposal

Expose these options through `host.json` and the standard app-setting override mechanism, for example:

```json
{
"primaryHostCoordinator": {
"leaseTimeout": "00:01:00",
"renewalInterval": "00:00:30"
}
}
```

with equivalent overrides such as:

```text
AzureFunctionsJobHost__primaryHostCoordinator__leaseTimeout=00:01:00
AzureFunctionsJobHost__primaryHostCoordinator__renewalInterval=00:00:30
```

The exact section name is not important.

The existing 15-second lease / 12-second renewal behavior should remain the default. Customers who opt into longer values would explicitly accept the corresponding failover tradeoff.

## Benefit

For one continuously active host:

| Configuration | Monthly renewals | Reduction |
|---|---:|---:|
| Current: 15s lease / 12s renewal | ~223,200 | — |
| 60s lease / 30s renewal | ~89,280 | **60%** |
| 60s lease / 57s renewal | ~46,990 | **79%** |

`60s / 30s` keeps more retry margin; `60s / 57s` minimizes transactions while preserving the current `LeaseTimeout - 3s` strategy.

Exposing both settings lets customers choose that tradeoff without changing existing defaults.

## Related issues

- Azure/azure-functions-host#2592 — Improve Host Lock Renewals
- Azure/azure-functions-host#11765 — Cost Regression due to added Health Check when using GPv2 Storage

#2592 already discusses this renewal strategy from a reliability perspective. This request is specifically to expose the existing coordinator options as an **opt-in customer setting** for workloads that want to choose their own storage-cost/failover tradeoff.

## Environment

```text
Plan: Azure Functions Flex Consumption
Runtime: Functions v4
Worker: Node.js
Storage: GPv2
Authentication: Managed Identity / OAuth
Observed lease: azure-webjobs-hosts/locks//host
Observed renewal cadence: ~12 seconds
```

Contributor guide

Open the contributing guide

Research direction

Start by locating PrimaryHostCoordinatorOptions and PrimaryHostCoordinator, then trace how host.json and AzureFunctionsJobHost app-setting overrides are bound. Confirm the existing 15-second lease and 12-second renewal defaults, the allowed TimeSpan values, and how an opt-in configuration would preserve them when unset; done means both settings can be configured without changing current defaults.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.