Lua: Change the TLS callback function type of ThreadLocalState to Upd…#11944
Lua: Change the TLS callback function type of ThreadLocalState to Upd…#11944snowp merged 10 commits intoenvoyproxy:masterfrom
Conversation
…ateCb Signed-off-by: wbpcode <comems@msn.com>
|
A related issue is #10241. But I can't fully confirm that this PR will definitely solve the issue. Because I cannot reproduce the issue directly in my environment. The only way I found to reproduce the issue is to cancel the repeated listener check first, and then add two listeners with the same name in the first xDS response, which will trigger this crash. In this scenario, the crash problem was indeed solved by this PR. |
|
Looks good. Could you provide a test for this case, please? Thanks! |
I think for this case, it may be difficult to design a good test case, because it is difficult to reproduce this crash. Anyway, I will try it. |
Signed-off-by: wbpcode <comems@msn.com>
|
Add a new test for ThreadLocalState. @dio |
|
If the type of callback is not modified, running this test directly will result in a crash (as follows). After changing the type of the callback function to |
Signed-off-by: wbpcode <comems@msn.com>
Signed-off-by: wbpcode <comems@msn.com>
dio
left a comment
There was a problem hiding this comment.
Overall looks good. Flushing some comments and questions.
| uint64_t ThreadLocalState::registerGlobal(const std::string& global) { | ||
| tls_slot_->runOnAllThreads([this, global]() { | ||
| LuaThreadLocal& tls = tls_slot_->getTyped<LuaThreadLocal>(); | ||
| tls_slot_->runOnAllThreads([global](ThreadLocal::ThreadLocalObjectSharedPtr ptr) -> auto { |
There was a problem hiding this comment.
Does spelling out -> auto (-> ThreadLocal::ThreadLocalObjectSharedPtr) here will be a problem for clang-tidy?
There was a problem hiding this comment.
From the existing code, it is acceptable to spell out the return type or not.
There was a problem hiding this comment.
Anyway, I will remove it to make the code more concise.
| tls_slot_->runOnAllThreads([this, global]() { | ||
| LuaThreadLocal& tls = tls_slot_->getTyped<LuaThreadLocal>(); | ||
| tls_slot_->runOnAllThreads([global](ThreadLocal::ThreadLocalObjectSharedPtr ptr) -> auto { | ||
| ASSERT(std::dynamic_pointer_cast<LuaThreadLocal>(ptr)); |
| // Start a new worker thread to execute the callback functions in the worker dispatcher. | ||
| Thread::ThreadPtr thread = Thread::threadFactoryForTest().createThread([this]() { | ||
| worker_dispatcher_->run(Event::Dispatcher::RunType::Block); | ||
| // Verify we have the expected dispatcher for the new thread thread. |
|
@snowp, when you have time, could you help to take a look on the test validity? Thanks! |
Signed-off-by: wbpcode <comems@msn.com>
|
#12018 is merged. Please sync your branch with head to fix the CI (Linux-x64 asan) issue. Thanks! |
|
|
Could you take the time to push this PR to the next step? Thanks. @snowp |
snowp
left a comment
There was a problem hiding this comment.
Thanks this makes sense, just one question.
| }; | ||
|
|
||
| // Test whether ThreadLocalState can be safely released. | ||
| TEST_F(ThreadSafeTest, StateDestructedBeforeWorkerRun) { |
There was a problem hiding this comment.
Does this test fail without the code change in this PR?
There was a problem hiding this comment.
Yes, it will be a crash.
|
🤷♀️ nothing to rebuild. |
envoyproxy#11944) Change the type of ThreadLocalState's TLS callback to UpdateCb. Through this method, we can avoid capturing this (ThreadLocalState instance) in the callback function, and avoid memory security problems caused by the inconsistency between the lifetime of the ThreadLocalSate instance and the lifetime of the callback function. Signed-off-by: wbpcode <comems@msn.com> Signed-off-by: Kevin Baichoo <kbaichoo@google.com>
envoyproxy#11944) Change the type of ThreadLocalState's TLS callback to UpdateCb. Through this method, we can avoid capturing this (ThreadLocalState instance) in the callback function, and avoid memory security problems caused by the inconsistency between the lifetime of the ThreadLocalSate instance and the lifetime of the callback function. Signed-off-by: wbpcode <comems@msn.com> Signed-off-by: scheler <santosh.cheler@appdynamics.com>
Lua: Change the TLS callback function type of ThreadLocalState to Upd… (envoyproxy#11944) Update LuaJIT patch - remove MAP_32BIT (envoyproxy#10867) Signed-off-by: wbpcode <comems@msn.com> Signed-off-by: John Murray <me@johnmurray.io> Signed-off-by: Yuchen Dai <silentdai@gmail.com> Change-Id: I62739dc1c3250fcff755d0a6208ec4f78cda695b
Signed-off-by: wbpcode comems@msn.com
Change the type of ThreadLocalState's TLS callback to UpdateCb. Through this method, we can avoid capturing
this(ThreadLocalState instance) in the callback function, and avoid memory security problems caused by the inconsistency between the lifetime of the ThreadLocalSate instance and the lifetime of the callback function.This modification is at least harmless.
Commit Message:
Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Deprecated:]