From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 409611A265F0; Wed, 4 Mar 2026 16:44:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 409611A265F0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1772631881; bh=pXKRyEWMSLCtXmT04fCpN+VNFry9iE0Oo03ZGDn/JfE=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=f8LYReb6kTbWdIbbhbR76dvrb8gACex0ThaU5+mTK7HP/yMfosn1tQBjbaw5bhe62 +83e4LzsWrRf0QgqeIgrv/U6HJ2K7CESRkp2Zoo+DOFShmXtuRsKCsdHqqV9bTI/0Q Bk8L8ldm9Y2udHrTsoFvrxGKjdeyO9BsTmy95Yl8= Received: from send243.i.mail.ru (send243.i.mail.ru [95.163.59.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id EAD8E19AD71C for ; Wed, 4 Mar 2026 16:44:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EAD8E19AD71C Received: by exim-smtp-558f87dcd7-8hpd7 with esmtpa (envelope-from ) id 1vxmWk-00000000Kyb-3sxs; Wed, 04 Mar 2026 16:44:39 +0300 Content-Type: multipart/alternative; boundary="------------DKFqDLZXFEt0EdgJKCNZs8U1" Message-ID: <26109d50-0770-4007-ba9e-1b2f747c8a3d@tarantool.org> Date: Wed, 4 Mar 2026 16:44:38 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org References: <20260302082317.4082-1-skaplun@tarantool.org> In-Reply-To: <20260302082317.4082-1-skaplun@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9FE49BA1A5307ACBF9C3F4B87650A8CB2C43232B544DD0C6A00894C459B0CD1B9BAFA7B66B0A078D315C513EAE8123D4D00D9C0786F19F902764D5F8EC6E69D3752B81C99D67B1670 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE731D82F3F177D3BCDEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB55337566CF7C7957E4725328E7D7973CE847FCDC6FF703142B0F87DA4B6C255965EFF2D6389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0A29E2F051442AF778941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6D52CD31C43BF465FCC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C2249E9403B922447A66876E601842F6C81A12EF20D2F80756B5FB606B96278B59C4276E601842F6C81A127C277FBC8AE2E8B0071B731DD7ECF4A3AA81AA40904B5D99C9F4D5AE37F343AD1F44FA8B9022EA23BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B093A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E7356436AE5DD6441DC7C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A5AC7953ACC9C0B5955002B1117B3ED6967041F2DE342CBDDCB91D2EB2DEE3878C823CB91A9FED034534781492E4B8EEAD85CCBA673D36D1A4BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE191716CD42B3DD1D34CAB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D6596EB442B856D3F07EFFCEE033B94588981A5BBAAE22BA4057C760D5E27433B1A116BC6F0BCAF02B67B8341EE9D5BE9A0A2138656939E99DF0AA3782D0550BCBDA947B0E55948D8F408CD93680B12512CF4C41F94D744909CE2512F26BEC029E55448553D2254B8D95CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVbwN8XFWZxQUzTmrSz6cAXU= X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F2588458E9DB41CC9678C7DACC811723C208B4174178CFCC26E650822DF9CF5F39CC750B645D15D82EE4B272BD6E4642A116CA93524AA66B5ACBE6721EF430B9A63E2A504198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix reporting of an error during error handling. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This is a multi-part message in MIME format. --------------DKFqDLZXFEt0EdgJKCNZs8U1 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Sergey! thanks for the patch! LGTM with minor comments below. Sergey On 3/2/26 11:23, Sergey Kaplun wrote: > From: Mike Pall > > Reported by Sergey Kaplun. > > (cherry picked from commit 54a162688ed25902122077149df9b456bc5a763e) > > For now, any non-ERRRUN error in the error handling preserves its own > error message. Thus, instead of the 'error in error handling', the > caller gets an 'out of memory' or 'stack overflow' error. > > This patch adds the corresponding status check in the custom error > handlers. The "error in error handling" string is also added to the > preallocated strings to avoid OOM during error message allocation. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#12134 > --- > > Branch:https://github.com/tarantool/luajit/tree/skaplun/lj-1381-fix-errmsg-in-err-handler > Related issues: > *https://github.com/LuaJIT/LuaJIT/issues/1381 > *https://github.com/tarantool/tarantool/issues/12134 > > src/lj_err.c | 10 ++++ > src/lj_state.c | 1 + > ...lj-1381-fix-errmsg-in-err-handler.test.lua | 50 +++++++++++++++++++ > test/tarantool-tests/utils/CMakeLists.txt | 1 + > 4 files changed, 62 insertions(+) > create mode 100644 test/tarantool-tests/lj-1381-fix-errmsg-in-err-handler.test.lua > > diff --git a/src/lj_err.c b/src/lj_err.c > index 80dca847..51baee8d 100644 > --- a/src/lj_err.c > +++ b/src/lj_err.c > @@ -775,9 +775,17 @@ LJ_NOINLINE GCstr *lj_err_str(lua_State *L, ErrMsg em) > return lj_str_newz(L, err2msg(em)); > } > > +LJ_NORET LJ_NOINLINE static void lj_err_err(lua_State *L) > +{ > + setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRERR)); > + lj_err_throw(L, LUA_ERRERR); > +} > + > /* Out-of-memory error. */ > LJ_NOINLINE void lj_err_mem(lua_State *L) > { > + if (L->status == LUA_ERRERR) > + lj_err_err(L); > if (L->status == LUA_ERRERR+1) /* Don't touch the stack during lua_open. */ > lj_vm_unwind_c(L->cframe, LUA_ERRMEM); > if (LJ_HASJIT) { > @@ -874,6 +882,8 @@ LJ_NOINLINE void LJ_FASTCALL lj_err_run(lua_State *L) > /* Stack overflow error. */ > void LJ_FASTCALL lj_err_stkov(lua_State *L) > { > + if (L->status == LUA_ERRERR) > + lj_err_err(L); > lj_debug_addloc(L, err2msg(LJ_ERR_STKOV), L->base-1, NULL); > lj_err_run(L); > } > diff --git a/src/lj_state.c b/src/lj_state.c > index 053e5ec9..8e46fa6d 100644 > --- a/src/lj_state.c > +++ b/src/lj_state.c > @@ -201,6 +201,7 @@ static TValue *cpluaopen(lua_State *L, lua_CFunction dummy, void *ud) > lj_meta_init(L); > lj_lex_init(L); > fixstring(lj_err_str(L, LJ_ERR_ERRMEM)); /* Preallocate memory error msg. */ > + fixstring(lj_err_str(L, LJ_ERR_ERRERR)); /* Preallocate err in err msg. */ > g->gc.threshold = 4*g->gc.total; > #if LJ_HASFFI > lj_ctype_initfin(L); > diff --git a/test/tarantool-tests/lj-1381-fix-errmsg-in-err-handler.test.lua b/test/tarantool-tests/lj-1381-fix-errmsg-in-err-handler.test.lua > new file mode 100644 > index 00000000..a789683e > --- /dev/null > +++ b/test/tarantool-tests/lj-1381-fix-errmsg-in-err-handler.test.lua > @@ -0,0 +1,50 @@ > +local tap = require('tap') > + > +-- Test file to demonstrate LuaJIT incorrect error message for the > +-- errors in the error handler. > +-- See also:https://github.com/LuaJIT/LuaJIT/issues/1381. > + > +local test = tap.test('lj-1381-fix-errmsg-in-err-handler') > + > +local allocinject = require('allocinject') > + > +test:plan(6) > + > +-- Disable JIT to avoid multiple invocation of the error handler. > +-- See alsohttps://github.com/LuaJIT/LuaJIT/issues/1382. > +jit.off() > + > +-- OOM on the creation of ERRERR message. > +coroutine.wrap(function() > + allocinject.enable_null_alloc() > + local st, msg = xpcall(error, error) > + allocinject.disable() > +test:ok(not st, 'OOM ERRERR incorrect status') > + -- Prevent preallocated error message. > +test:ok(msg:match('error in ' .. 'error handling'), > + 'OOM ERRERR incorrect errmsg: ' .. msg) > +end)() > + > +-- OOM in the error handler. > +coroutine.wrap(function() > + local function errmem() local _ = {} end > + allocinject.enable_null_alloc() > + local st, msg = xpcall(error, errmem) > + allocinject.disable() > +test:ok(not st, 'OOM incorrect status') > + -- Prevent preallocated error message. > +test:ok(msg:match('error in ' .. 'error handling'), > + 'OOM incorrect errmsg: ' .. msg) > +end)() > + > +-- STKOV in the error handler. Why abbreviation is used? May be "stack overflow"? Feel free to ignore. > +coroutine.wrap(function() > + local function stkov() stkov() end > + local st, msg = xpcall(error, stkov) > +test:ok(not st, 'STKOV incorrect status') > + -- Prevent preallocated error message. > +test:ok(msg:match('error in ' .. 'error handling'), > + 'STKOV incorrect errmsg: ' .. msg) > +end)() > + > +test:done(true) > diff --git a/test/tarantool-tests/utils/CMakeLists.txt b/test/tarantool-tests/utils/CMakeLists.txt > index a16424ec..ec792b62 100644 > --- a/test/tarantool-tests/utils/CMakeLists.txt > +++ b/test/tarantool-tests/utils/CMakeLists.txt > @@ -5,5 +5,6 @@ list(APPEND tests > lj-1247-fin-tab-rehashing-on-trace.test.lua > lj-1249-loadfile-fd-leak.test.lua > lj-1298-oom-on-concat-recording.test.lua > + lj-1381-fix-errmsg-in-err-handler.test.lua > ) > BuildTestCLib(allocinject allocinject.c "${tests}") --------------DKFqDLZXFEt0EdgJKCNZs8U1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hi, Sergey!

thanks for the patch! LGTM with minor comments below.

Sergey

On 3/2/26 11:23, Sergey Kaplun wrote:
From: Mike Pall <mike>

Reported by Sergey Kaplun.

(cherry picked from commit 54a162688ed25902122077149df9b456bc5a763e)

For now, any non-ERRRUN error in the error handling preserves its own
error message. Thus, instead of the 'error in error handling', the
caller gets an 'out of memory' or 'stack overflow' error.

This patch adds the corresponding status check in the custom error
handlers. The "error in error handling" string is also added to the
preallocated strings to avoid OOM during error message allocation.

Sergey Kaplun:
* added the description and the test for the problem

Part of tarantool/tarantool#12134
---

Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1381-fix-errmsg-in-err-handler
Related issues:
* https://github.com/LuaJIT/LuaJIT/issues/1381
* https://github.com/tarantool/tarantool/issues/12134

 src/lj_err.c                                  | 10 ++++
 src/lj_state.c                                |  1 +
 ...lj-1381-fix-errmsg-in-err-handler.test.lua | 50 +++++++++++++++++++
 test/tarantool-tests/utils/CMakeLists.txt     |  1 +
 4 files changed, 62 insertions(+)
 create mode 100644 test/tarantool-tests/lj-1381-fix-errmsg-in-err-handler.test.lua

diff --git a/src/lj_err.c b/src/lj_err.c
index 80dca847..51baee8d 100644
--- a/src/lj_err.c
+++ b/src/lj_err.c
@@ -775,9 +775,17 @@ LJ_NOINLINE GCstr *lj_err_str(lua_State *L, ErrMsg em)
   return lj_str_newz(L, err2msg(em));
 }
 
+LJ_NORET LJ_NOINLINE static void lj_err_err(lua_State *L)
+{
+  setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRERR));
+  lj_err_throw(L, LUA_ERRERR);
+}
+
 /* Out-of-memory error. */
 LJ_NOINLINE void lj_err_mem(lua_State *L)
 {
+  if (L->status == LUA_ERRERR)
+    lj_err_err(L);
   if (L->status == LUA_ERRERR+1)  /* Don't touch the stack during lua_open. */
     lj_vm_unwind_c(L->cframe, LUA_ERRMEM);
   if (LJ_HASJIT) {
@@ -874,6 +882,8 @@ LJ_NOINLINE void LJ_FASTCALL lj_err_run(lua_State *L)
 /* Stack overflow error. */
 void LJ_FASTCALL lj_err_stkov(lua_State *L)
 {
+  if (L->status == LUA_ERRERR)
+    lj_err_err(L);
   lj_debug_addloc(L, err2msg(LJ_ERR_STKOV), L->base-1, NULL);
   lj_err_run(L);
 }
diff --git a/src/lj_state.c b/src/lj_state.c
index 053e5ec9..8e46fa6d 100644
--- a/src/lj_state.c
+++ b/src/lj_state.c
@@ -201,6 +201,7 @@ static TValue *cpluaopen(lua_State *L, lua_CFunction dummy, void *ud)
   lj_meta_init(L);
   lj_lex_init(L);
   fixstring(lj_err_str(L, LJ_ERR_ERRMEM));  /* Preallocate memory error msg. */
+  fixstring(lj_err_str(L, LJ_ERR_ERRERR));  /* Preallocate err in err msg. */
   g->gc.threshold = 4*g->gc.total;
 #if LJ_HASFFI
   lj_ctype_initfin(L);
diff --git a/test/tarantool-tests/lj-1381-fix-errmsg-in-err-handler.test.lua b/test/tarantool-tests/lj-1381-fix-errmsg-in-err-handler.test.lua
new file mode 100644
index 00000000..a789683e
--- /dev/null
+++ b/test/tarantool-tests/lj-1381-fix-errmsg-in-err-handler.test.lua
@@ -0,0 +1,50 @@
+local tap = require('tap')
+
+-- Test file to demonstrate LuaJIT incorrect error message for the
+-- errors in the error handler.
+-- See also: https://github.com/LuaJIT/LuaJIT/issues/1381.
+
+local test = tap.test('lj-1381-fix-errmsg-in-err-handler')
+
+local allocinject = require('allocinject')
+
+test:plan(6)
+
+-- Disable JIT to avoid multiple invocation of the error handler.
+-- See also https://github.com/LuaJIT/LuaJIT/issues/1382.
+jit.off()
+
+-- OOM on the creation of ERRERR message.
+coroutine.wrap(function()
+  allocinject.enable_null_alloc()
+  local st, msg = xpcall(error, error)
+  allocinject.disable()
+  test:ok(not st, 'OOM ERRERR incorrect status')
+  -- Prevent preallocated error message.
+  test:ok(msg:match('error in ' .. 'error handling'),
+          'OOM ERRERR incorrect errmsg: ' .. msg)
+end)()
+
+-- OOM in the error handler.
+coroutine.wrap(function()
+  local function errmem() local _ = {} end
+  allocinject.enable_null_alloc()
+  local st, msg = xpcall(error, errmem)
+  allocinject.disable()
+  test:ok(not st, 'OOM incorrect status')
+  -- Prevent preallocated error message.
+  test:ok(msg:match('error in ' .. 'error handling'),
+          'OOM incorrect errmsg: ' .. msg)
+end)()
+
+-- STKOV in the error handler.
Why abbreviation is used? May be "stack overflow"? Feel free to ignore.
+coroutine.wrap(function()
+  local function stkov() stkov() end
+  local st, msg = xpcall(error, stkov)
+  test:ok(not st, 'STKOV incorrect status')
+  -- Prevent preallocated error message.
+  test:ok(msg:match('error in ' .. 'error handling'),
+          'STKOV incorrect errmsg: ' .. msg)
+end)()
+
+test:done(true)
diff --git a/test/tarantool-tests/utils/CMakeLists.txt b/test/tarantool-tests/utils/CMakeLists.txt
index a16424ec..ec792b62 100644
--- a/test/tarantool-tests/utils/CMakeLists.txt
+++ b/test/tarantool-tests/utils/CMakeLists.txt
@@ -5,5 +5,6 @@ list(APPEND tests
   lj-1247-fin-tab-rehashing-on-trace.test.lua
   lj-1249-loadfile-fd-leak.test.lua
   lj-1298-oom-on-concat-recording.test.lua
+  lj-1381-fix-errmsg-in-err-handler.test.lua
 )
 BuildTestCLib(allocinject allocinject.c "${tests}")
--------------DKFqDLZXFEt0EdgJKCNZs8U1--