From 6b2bd5674f339598d5c1008f8aa4827f94b8398c Mon Sep 17 00:00:00 2001 From: Balasubramania Pillai Date: Wed, 4 Mar 2026 11:46:08 -0500 Subject: [PATCH 1/2] TASK-209191 block global trace while inheriting thread data --- src/lgc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lgc.c b/src/lgc.c index 116a058..159e284 100644 --- a/src/lgc.c +++ b/src/lgc.c @@ -1624,12 +1624,16 @@ void luaC_inherit_thread(lua_State *L, lua_State *th) { int i; GCheader *steal, *tmp; + thr_State *pt; if (th->heap == NULL) { // already done return; } + pt = luaC_get_per_thread(L); + block_collector(L, pt); + /* when a thread is reclaimed, the executing thread * needs to steal its contents */ lock_all_threads(); @@ -1673,6 +1677,8 @@ void luaC_inherit_thread(lua_State *L, lua_State *th) TAILQ_REMOVE(&G(L)->all_heaps, th->heap, heaps); unlock_all_threads(); + unblock_collector(L, pt); + free(th->heap); th->heap = NULL; From b88bfd0800adaad4e1d085cdb3d5269bbcf291b7 Mon Sep 17 00:00:00 2001 From: Balasubramania Pillai Date: Wed, 4 Mar 2026 12:21:41 -0500 Subject: [PATCH 2/2] TASK-209191 fix lock ordering --- src/lgc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lgc.c b/src/lgc.c index 159e284..d829d2a 100644 --- a/src/lgc.c +++ b/src/lgc.c @@ -1632,12 +1632,13 @@ void luaC_inherit_thread(lua_State *L, lua_State *th) } pt = luaC_get_per_thread(L); - block_collector(L, pt); /* when a thread is reclaimed, the executing thread * needs to steal its contents */ lock_all_threads(); + block_collector(L, pt); + if (TEST_INHERIT_THREAD_DELAY_MS > 0) { /* TR-1945: Both global trace and thread delref will grab * the "all threads" lock. To induce false contention on that lock @@ -1675,10 +1676,10 @@ void luaC_inherit_thread(lua_State *L, lua_State *th) make_grey(L, steal); } TAILQ_REMOVE(&G(L)->all_heaps, th->heap, heaps); - unlock_all_threads(); - unblock_collector(L, pt); + unlock_all_threads(); + free(th->heap); th->heap = NULL;