-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dispatch inline Lua code in per filter config of Lua filter by RDS #12460
Comments
In order to ensure that TLS will not be modified on the worker thread, I destroy ThreadLocalState by using the dispatcher of the main thread. |
Sorry I'm not sure I follow the proposal. Can you explain in more detail potentially? |
In Lua filter, we use PerLuaCodeSetup (PerLuaCodeSetup contains a ThreadLocalState member) to parse and manage a Lua script. When we need to dynamically deliver Lua scripts through RDS, we will also create a PerLuaCodeSetup object associated with a specific route. The problem is that when the routes table is updated, the PerLuaCodeSetup in the old route configuration will be destructed in the worker thread, which will lead to the modification of TLS in the same worker thread, which will eventually bring thread safety issues. In the new implementation, I plan to use the dispatch (dispatch.deferredDelete) of the main thread to assist in the destruction of PerLuaCodeSetup. Ensure that all ThreadLocalState memeber of PerLuaCodeSetup can only be destructed on the main thread to avoid thread safety issues. But now I cannot fully confirm whether this modification can circumvent all the problems. @mattklein123 PS: Maybe I submit a new PR directly and let the code explain how I did it (very simple way), if there is a problem, slowly improve it ? |
Don't you need a notification of route change though? I think that is what is missing. Otherwise you have to do a dance in which you bounce back and forth between the workers and main thread. I think that if you were able to get a callback when the route table is updated you could potentially walk the table and pre-create Lua code for all routes and then TLS update that out to worker threads? cc @kyessenov @jplevyak @lizan @dio as this is a similar issue that we would eventually want to solve for WASM also I think. |
If I understand what you mean correctly, in fact, this is what I do now. When the route table is updated, all Lua codes in the new route table will be parsed and corresponding When all the creation is completed, TLS will update the route table to each worker thread. At the same time, the old route table will be destroyed on a thread (the thread that updated the route table last). All PerLuaCodeSetup in the old route table will also be destroyed. But ThreadLocalState in the PerLuaCodeSetup will be handled specially and will be destructed by the dispatcher of the main thread. |
You mean in the current code or in your proposed patch? We don't have any route table update callbacks right now. I think to allow RDS updates you would need this. |
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions. |
This is done. #11235. |
This is a supplement to PR #11235. Due to thread safety issues, the function of directly dispatch Lua code in per filter config through RDS is removed from #11235. Now, I am going to take some time to finalize it.
Although I have done some tests in my own environment, I am still worried about whether there will be problems that I have not considered. So I hope to get some opinions from the community.
For related background, please check issue #3124, #9279 and PR #11235.
The text was updated successfully, but these errors were encountered: