Hey everyone! I have a small race-condition issue and I am looking to get a better understanding of how Lua/OpenResty works. My setup is as follows and you can view it in code here: https://pastebin.com/KA0FbzAk
- I have a BaseModule that provides a new() method for extension.
- The BaseModule is extended twice, in two other separate modules (let’s say FirstExtendedBaseModule and SecondExtendedBaseModule).
- Both extended modules accept a config table inside the ‘constructor’ (say base_config).
- The SecondExtendedBaseModule provides a method (say doSomething) that requires the FirstExtendedBaseModule, instantiates it using self.base_config and runs one of its methods inside one of its methods as well (let’s say doSomething as well).
- The SecondExtendedBaseModule:doSomething() method is instantiated inside a content_by_lua_block in an nginx location, after the module is required.
Once the FirstExtendedBaseModule’s method finishes running, any property’s value existent on the self.base_config may change under heavy load due to a race-condition.
Based on the documentation available, my intuition is that the issue happens because modules are cached per worker when loaded as well as any data they provide. Given that self.base_config is a table and it’s passed by reference, under heavy load the values may change since the worker may reference the table in the heap from two different coroutines.
Can anyone confirm or provide more insights or whether my judgement is correct? I am not very familiar with OpenResty/Lua’s internals.