membphis commented on PR #14101:
URL: https://github.com/apache/apisix/pull/14101#issuecomment-6436506934

   **[P2] Baseline eviction can repeatedly replay historical stream bytes**
   
   Approved the first-session undercount fix. Please decide whether to address 
this edge case in this PR or track it as a follow-up; this comment is not a 
merge requirement.
   
   In `publish_stream_bytes`, `published = dict:get(key) or 0` treats an 
evicted baseline as a never-published slot. If the corresponding Counter 
survives, the next collection adds the slot's full lifetime total again. 
Repeated baseline loss can repeat this overcount, even without new traffic.
   
   I reproduced this using the actual function in a focused LuaJIT check with 
dictionary/Counter substitutes: with the zone total fixed at 15, removing the 
baseline twice changed the Counter from 15 to 30 to 45. This was not a real 
gateway memory-pressure test.
   
   `ngx.shared.DICT:set` can succeed while forcibly evicting other valid 
entries ([OpenResty 
documentation](https://github.com/openresty/lua-nginx-module#ngxshareddictset)).
   
   A possible fix is to keep publication baselines in separate, non-evicting 
storage with explicit capacity-failure handling, or introduce reliable state 
that distinguishes a new slot from lost publication state. A regression should 
cover repeated baseline loss while the Counter remains and the zone total does 
not change.
   
   Leaving the scope decision to the author: protect this case here, or track 
it separately.


-- 
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