bug: limit-conn Redis counters split across workers when runtime _meta.priority mutation affects cached conf_version
Current Behavior
In a deployment running Apache APISIX 3.18.0, the built-in limit-conn plugin generated two Redis keys for the same Plugin Config, consumer, and route, despite all sampled workers using the same resource revision.
limit_conn:/apisix/plugin_configs/10001:1686267894:credential-17 ui-route-76
limit_conn:/apisix/plugin_configs/10001:2979992090:credential-17 ui-route-76
Both keys received new requests during the same test window; this was not just an old key remaining after a configuration update. Requests belonging to both keys were found in the access logs of one APISIX instance.
A captured Redis trace used an effective limit of 5 for both keys and showed five admissions (ZADD) into one key and three into the other before the first observed release. The intended shared limit was therefore split into independent counters. Redis command execution itself did not show a check/add race.
Evidence ruling out different etcd resource versions
All three etcd endpoints belonged to the same cluster and returned identical values for /apisix/plugin_configs/10001:
mod_revision: 66367
resource_sha256: 045d9dc669258bd50482a8062e255282c1adc01d27efdf946b54a750ecef16c9
limit_conn_sha256: 2a68c2b0c9200b058fdd0e99ef3ba11797fb2002675d1007ee419c1074cb819b
A runtime snapshot from all 16 numbered request workers in one APISIX instance showed:
| Field | 13 workers | 3 workers |
|---|---|---|
| Resource revision | 66367 | 66367 |
| Parent resource revision | 66367 | 66367 |
| Cached conf._version | 2979992090 | 1686267894 |
| Current _meta.priority | 1003 | 1003 |
| Current _skip_rewrite_in_consumer | true | true |
| Current _from_consumer | nil | nil |
Removing only _meta.priority reproduced exactly the other cached version used in Redis keys.
Workaround verified in this deployment
Explicitly setting limit-conn._meta.priority to its default value, 1003, in the published plugin configuration resolved the observed counter split. Existing _meta.filter conditions were retained.
This is an observed workaround, not a claim that every other runtime configuration mutation has been fixed.
Expected Behavior
For the same Plugin Config revision and resolved limiting key, workers should share the intended Redis concurrency counter. Omitting the default priority should not make counter identity depend on the order in which workers process requests.
In particular, internally adding a default priority should not leave different workers using different cached configuration versions for the same logical policy.
Error Logs
These are representative diagnostic outputs from two request workers, condensed to the relevant fields:
{
"process_type": "worker",
"worker_id": 8,
"pid": 59,
"resource_revision": "66367",
"parent_revision": "66367",
"cached_version": "2979992090",
"priority": "1003",
"skip_rewrite": "true",
"stable_now": "1686267894",
"without_priority": "2979992090",
"without_skip": "1376740183",
"without_both": "301125200"
}
{
"process_type": "worker",
"worker_id": 7,
"pid": 58,
"resource_revision": "66367",
"parent_revision": "66367",
"cached_version": "1686267894",
"priority": "1003",
"skip_rewrite": "true",
"stable_now": "1686267894",
"without_priority": "2979992090",
"without_skip": "1376740183",
"without_both": "301125200"
}
stable_now excludes _version before hashing; it does not hash the cache field back into the configuration. The without_* variants alter copies only. The diagnostics were run through the existing inspect mechanism without reloading workers for the snapshots.
Steps to Reproduce
Observed deployment and diagnostic sequence
The following describes the actual deployment investigation. It is not yet a standalone, clean-image end-to-end reproducer.
- Run APISIX 3.18.0 with multiple workers and a shared Redis backend.
- Configure the built-in
limit-connunder a Plugin Config, without explicitly setting_meta.priority. - Use authenticated requests and the following rule shape. The Redis address is redacted; the field names and rule expressions are retained.
{
"policy": "redis",
"redis_host": "REDIS_HOST_REDACTED",
"redis_port": 30802,
"default_conn_delay": 0.1,
"rejected_code": 429,
"rejected_msg": "Rate limit reached for CONN",
"rules": [
{
"conn": "$consumer_conn_limit",
"burst": 0,
"key": "$consumer_name $route_id"
}
],
"_meta": {
"filter": [
["consumer_conn_limit", "~~", "^[1-9][0-9]*$"]
]
}
}
consumer_conn_limit is a deployment-specific request variable. It was initially configured as 10; the captured Redis admission test used 5. This configuration fragment alone does not reproduce the deployment's variable-injection or authentication setup. The CRC32 values above are original observations, not expected hashes of this redacted JSON.
- During the failing test, without updating the Plugin Config, observe two Redis keys for the same consumer and route and new admissions into both.
- Inspect each worker's configuration resource revision, cached
_version, and runtime fields. - On configuration copies, recompute CRC32 after excluding
_version, then repeat after additionally removing_meta.priority. The second calculation matches the other live Redis-key version. - Publish the same policy with
_meta.priority: 1003explicitly included and retest. The reporter observed that this change resolved the issue.
Reproduction limitation
The deployment includes custom extensions and ai-proxy-multi. We initially observed a correlation with the http_429 fallback path, but have not established that fallback is necessary or directly responsible for the priority mutation.
The original incident was investigated on the built-in limit-conn configuration. A separate custom limiter was reviewed later; it also calls apisix.plugin.conf_version(conf) and is not an independent upstream reproduction.
We have not yet isolated the precise first request/route that causes priority backfilling in each worker, or reproduced the complete request sequence on a clean image with all custom extensions removed. We are not claiming that every deployment with 16 workers reproduces the problem.
Source Analysis
In 3.18.0, plugin.filter() fills missing _meta.priority fields on plugin configuration tables when custom sorting is needed. conf_version() caches a hash of the table on its first call, while limit-conn includes that cached hash in its Redis key. These paths are consistent with hashing before versus after default-priority insertion. The exact first mutation call in the deployment has not been traced.
Source references:
- [Priority backfilling in plugin.filter()](https://github.com/apache/apisix/blob/3.18.0/apisix/plugin.lua#L574-L605)
- [Cached plugin configuration version](https://github.com/apache/apisix/blob/3.18.0/apisix/plugin.lua#L913-L923)
- [limit-conn key generation](https://github.com/apache/apisix/blob/3.18.0/apisix/plugins/limit-conn/init.lua#L125-L139)
- [Default limit-conn priority](https://github.com/apache/apisix/blob/3.18.0/apisix/plugins/limit-conn.lua#L107-L112)
- [Plugin Config merging](https://github.com/apache/apisix/blob/3.18.0/apisix/plugin_config.lua#L63-L89)
- [Documented optional custom priority](https://apisix.apache.org/docs/apisix/3.18/terminology/plugin/#plugins-execution-order)
Suggested Fix / Regression Coverage
Please consider avoiding in-place mutation of plugin configuration for sorting, or deriving configuration identity from a normalized immutable snapshot rather than request-dependent fields.
A regression test should check that equivalent configurations produce a shared limiter key regardless of whether priority normalization precedes the first version calculation. A shared Plugin Config used by request paths with and without custom-priority sorting would be a useful integration test candidate; this is a proposed test, not a completed reproducer.
Simply clearing _version during active requests may switch counters while old requests remain registered, so counter migration and in-flight requests need consideration.
Related Issues
- #13584 / #13600 addressed consumer-level counter isolation using parent resource keys instead of context-level versions. This report concerns the plugin-level cached hash and runtime default-priority insertion, so it appears to be a distinct failure mechanism.
Environment
- APISIX version: 3.18.0, as reported by the deployment operator; exact image digest / version command output not collected in this report.
- Deployment: Docker Compose, three APISIX instances.
- Worker configuration:
worker_processes: auto; the examined instance had 16 request workers and no shutting-down workers at the captured process inspection. - Configuration backend: one three-member etcd cluster. All endpoints returned identical Plugin Config revision and content hashes.
- Limiting backend: shared Redis;
policy: redis,burst: 0. - Plugin Config: 10001; the incident was observed for one consumer/route pair.
- Custom extensions: present; a clean-image end-to-end reproduction is not yet available.
- Operating system, OpenResty/Nginx version, Redis version and etcd version: not collected yet; can be added before submission.
- Other APISIX versions: not runtime-tested for this report. Source inspection is not a claim of verified impact on another release.