BUG/MEDIUM: debug/lua: Use internal hlua function to dump the lua traceback

The commit reverts following commits:
  * 83926a04 BUG/MEDIUM: debug/lua: Don't dump the lua stack if not dumpable
  * a61789a1 MEDIUM: lua: Use a per-thread counter to track some non-reentrant parts of lua

Instead of relying on a Lua function to print the lua traceback into the
debugger, we are now using our own internal function (hlua_traceback()).
This one does not allocate memory and use a chunk instead. This avoids any
issue with a possible deadlock in the memory allocator because the thread
processing was interrupted during a memory allocation.

This patch relies on the commit "BUG/MEDIUM: debug/lua: Use internal hlua
function to dump the lua traceback". Both must be backported wherever the
patches above are backported, thus as far as 2.0
This commit is contained in:
Christopher Faulet 2021-03-24 14:52:24 +01:00
parent d09cc519bd
commit cc2c4f8f4c
3 changed files with 5 additions and 19 deletions

View File

@ -51,7 +51,6 @@ void hlua_applet_tcp_fct(struct appctx *ctx);
void hlua_applet_http_fct(struct appctx *ctx);
struct task *hlua_process_task(struct task *task, void *context, unsigned int state);
extern THREAD_LOCAL unsigned int hlua_not_dumpable;
#else /* USE_LUA */
/************************ For use when Lua is disabled ********************/

View File

@ -264,13 +264,9 @@ void ha_task_dump(struct buffer *buf, const struct task *task, const char *pfx)
}
if (hlua && hlua->T) {
if (hlua_not_dumpable == 0) {
luaL_traceback(hlua->T, hlua->T, NULL, 0);
if (!append_prefixed_str(buf, lua_tostring(hlua->T, -1), pfx, '\n', 1))
b_putchr(buf, '\n');
}
else
chunk_appendf(buf, "Inside non-rentrant part, Stack traceback not available\n");
chunk_appendf(buf, "stack traceback:\n ");
append_prefixed_str(buf, hlua_traceback(hlua->T, "\n "), pfx, '\n', 0);
b_putchr(buf, '\n');
}
else
b_putchr(buf, '\n');

View File

@ -274,9 +274,6 @@ struct hlua_mem_allocator {
static struct hlua_mem_allocator hlua_global_allocator THREAD_ALIGNED(64);
/* > 0 if lua is in a non-rentrant part, thus with a non-dumpable stack */
THREAD_LOCAL unsigned int hlua_not_dumpable = 0;
/* These functions converts types between HAProxy internal args or
* sample and LUA types. Another function permits to check if the
* LUA stack contains arguments according with an required ARG_T
@ -8635,12 +8632,8 @@ static void *hlua_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
/* a limit of ~0 means unlimited and boot complete, so there's no need
* for accounting anymore.
*/
if (likely(~zone->limit == 0)) {
hlua_not_dumpable++;
ptr = realloc(ptr, nsize);
hlua_not_dumpable--;
return ptr;
}
if (likely(~zone->limit == 0))
return realloc(ptr, nsize);
if (!ptr)
osize = 0;
@ -8654,9 +8647,7 @@ static void *hlua_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
return NULL;
} while (!_HA_ATOMIC_CAS(&zone->allocated, &old, new));
hlua_not_dumpable++;
ptr = realloc(ptr, nsize);
hlua_not_dumpable--;
if (unlikely(!ptr && nsize)) // failed
_HA_ATOMIC_SUB(&zone->allocated, nsize - osize);