Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions source/extensions/filters/common/lua/lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ThreadLocalState::ThreadLocalState(const std::string& code, ThreadLocal::SlotAll
: tls_slot_(ThreadLocal::TypedSlot<LuaThreadLocal>::makeUnique(tls)) {

// First verify that the supplied code can be parsed.
CSmartPtr<lua_State, lua_close> state(lua_open());
CSmartPtr<lua_State, lua_close> state(luaL_newstate());
RELEASE_ASSERT(state.get() != nullptr, "unable to create new Lua state object");
luaL_openlibs(state.get());

Expand Down Expand Up @@ -90,7 +90,9 @@ CoroutinePtr ThreadLocalState::createCoroutine() {
return std::make_unique<Coroutine>(std::make_pair(lua_newthread(state), state));
}

ThreadLocalState::LuaThreadLocal::LuaThreadLocal(const std::string& code) : state_(lua_open()) {
ThreadLocalState::LuaThreadLocal::LuaThreadLocal(const std::string& code)
: state_(luaL_newstate()) {

RELEASE_ASSERT(state_.get() != nullptr, "unable to create new Lua state object");
luaL_openlibs(state_.get());
int rc = luaL_dostring(state_.get(), code.c_str());
Expand Down
4 changes: 3 additions & 1 deletion test/extensions/filters/http/lua/lua_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,9 @@ TEST_P(LuaIntegrationTest, BasicTestOfLuaPerRoute) {
// Test whether Rds can correctly deliver LuaPerRoute configuration.
TEST_P(LuaIntegrationTest, RdsTestOfLuaPerRoute) {
// When the route configuration is updated dynamically via RDS and the configuration contains an
// inline Lua code, Envoy may call lua_open in multiple threads to create new lua_State objects.
// inline Lua code, Envoy may call `luaL_newstate`
// (https://www.lua.org/manual/5.1/manual.html#luaL_newstate) in multiple threads to create new
// lua_State objects.
// During lua_State creation, 'LuaJIT' uses some static local variables shared by multiple threads
// to aid memory allocation. Although 'LuaJIT' itself guarantees that there is no thread safety
// issue here, the use of these static local variables by multiple threads will cause a TSAN alarm.
Expand Down