From 73f2d4cd178a065310e7d6c8a98141594cc85d27 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 2 Oct 2025 14:28:32 +0100 Subject: [PATCH] [Fix] Add full Lua traceback to HTTP callback errors Improved error diagnostics in lua_http_finish_handler by adding rspamd_lua_traceback handler. Now shows complete call stack with file names and line numbers when Lua HTTP callbacks fail, making debugging much easier. --- src/lua/lua_http.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 24452f1715..3330bc6ea5 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -377,6 +377,9 @@ lua_http_finish_handler(struct rspamd_http_connection *conn, L = lcbd.L; + lua_pushcfunction(L, &rspamd_lua_traceback); + int err_idx = lua_gettop(L); + lua_rawgeti(L, LUA_REGISTRYINDEX, cbd->cbref); /* Error */ lua_pushnil(L); @@ -420,11 +423,13 @@ lua_http_finish_handler(struct rspamd_http_connection *conn, rspamd_symcache_set_cur_item(cbd->task, cbd->item); } - if (lua_pcall(L, 4, 0, 0) != 0) { + if (lua_pcall(L, 4, 0, err_idx) != 0) { msg_info("callback call failed: %s", lua_tostring(L, -1)); lua_pop(L, 1); } + lua_pop(L, 1); /* Remove traceback function */ + REF_RELEASE(cbd); lua_thread_pool_restore_callback(&lcbd); -- 2.47.3