-
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
Lua: Change the TLS callback function type of ThreadLocalState to Upd… #11944
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good. Flushing some comments and questions.
@@ -71,8 +71,9 @@ int ThreadLocalState::getGlobalRef(uint64_t slot) { | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does spelling out -> auto
(-> ThreadLocal::ThreadLocalObjectSharedPtr
) here will be a problem for clang-tidy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And let's rename ptr
as previous
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the existing code, it is acceptable to spell out the return type or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this assert here?
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the new worker 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this test fail without the code change in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it will be a crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for verifying!
🤷♀️ nothing to rebuild. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
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:]