kong icon indicating copy to clipboard operation
kong copied to clipboard

feat(request-aware-table) add request aware table

Open samugi opened this issue 2 years ago • 2 comments

Summary

Add a request-aware table able to detect accesses from different requests.

Checklist

  • [x] The Pull Request has tests
  • [x] (na) There's an entry in the CHANGELOG
  • [x] (na) There is a user-facing docs PR against https://github.com/Kong/docs.konghq.com - PUT DOCS PR HERE

Full changelog

  • [Implement ...]

Issue reference

KAG-1570

samugi avatar Jun 06 '23 16:06 samugi

What is request aware table in comparison to ngx.ctx or kong.ctx.plugin|shared?

bungle avatar Jun 07 '23 05:06 bungle

What is request aware table in comparison to ngx.ctx or kong.ctx.plugin|shared?

I wondered that myself @bungle, thanks for bringing it up.

The main difference is that this table can detect race conditions and throw an error if they happen, instead of using separate scopes for each request to prevent them. Race condition checks (which currently require an access to ngx.var per request) would only be turned on during testing, to ensure the table is used properly (i.e. cleared before it's accessed by another request). This allows defining a table that is local to the module where it is instantiated, can be cleared at will, and does not rely on a shared context.

However, if the performance impact of accessing this table compared to using the context is not significant, we could solve the same problem just as in this PR, using kong.ctx.plugin to prevent race conditions in the first place.

I'd be curious to hear @dndx 's opinion as well

samugi avatar Jun 07 '23 09:06 samugi

@dndx could you take a look at this PR again? thx

AndyZhang0707 avatar Sep 14 '23 23:09 AndyZhang0707