janiussyafiq opened a new pull request, #13555:
URL: https://github.com/apache/apisix/pull/13555

   ### Description
   
   `apisix/utils/redis-schema.lua` builds limit-conn's `key_ttl` schema 
variants by **mutating the shared `policy_to_additional_properties` tables in 
place**:
   
   ```lua
   local limit_conn_redis_cluster_schema = 
policy_to_additional_properties["redis-cluster"]
   limit_conn_redis_cluster_schema.properties.key_ttl = {
       type = "integer", default = 3600,
   }
   ```
   
   Since this runs at module load, `key_ttl` (and its default of 3600) leaks 
into the base `redis` / `redis-cluster` tables that every other consumer of 
this module reuses. Observable effect today: `limit-count` and `limit-req` 
confs silently gain a `key_ttl = 3600` field during schema validation (defaults 
are applied to the conf), even though neither plugin understands the property. 
`limit-count`'s `core.table.deepcopy(redis_schema.schema)` doesn't help — it 
copies the already-mutated tables.
   
   This PR builds the limit-conn variants from a shallow copy of the shared 
base, so the extra property stays local to limit-conn:
   
   - the shared `redis` / `redis-cluster` tables no longer carry `key_ttl`
   - `limit-conn` behavior is unchanged (`key_ttl` still accepted, default 3600 
still applied)
   - `limit-count` / `limit-req` confs no longer get a foreign `key_ttl` 
injected; a stray explicit `key_ttl` on those plugins is still tolerated (their 
schemas do not reject additional properties) — it is just no longer injected
   
   New regression test `t/plugin/redis-schema.t` asserts the shared tables are 
clean, the limit-conn variants carry `key_ttl`, and validated 
`limit-count`/`limit-req` confs do not gain the field while `limit-conn` keeps 
its default/override behavior. The test fails on current master and passes with 
the fix.
   
   This also unblocks new consumers of `redis-schema` (e.g. the `ai-cache` 
plugin in #13424, which previously carried this fix in passing — extracted here 
so it can be reviewed on its own).
   
   #### Which issue(s) this PR fixes:
   
   None (pre-existing latent bug found while building on `redis-schema`).
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change (no doc change 
needed: internal schema utility; user-facing behavior of limit-conn unchanged)
   - [x] I have verified that this change is backward compatible


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to