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 BDCC26CB2C1; Fri, 24 Nov 2023 15:22:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BDCC26CB2C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1700828571; bh=n2Korl9fZOqJBHSI43R+V8tNiJkor9mf3KMKWzxQlSg=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=w+5vvgj7VF4wqlgnEqio3EUnVbPA6Cr14dxI+YPg/D6VT/LIlVY35jw0ZCDHIbNOA sSWNxbwU/lVsjFBF6D7gH8GN0B1C95Jj8UfASuc7GS/lfwRKeAChsK1WmRq+YcLk5w E6NmckuS7ZS0FOSmg3I8Hi4IPgmPvXqnGIeFLqwQ= Received: from smtp29.i.mail.ru (smtp29.i.mail.ru [95.163.41.68]) (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 22E306CB2C1 for ; Fri, 24 Nov 2023 15:22:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 22E306CB2C1 Received: by smtp29.i.mail.ru with esmtpa (envelope-from ) id 1r6VCr-000aQx-08; Fri, 24 Nov 2023 15:22:49 +0300 Message-ID: <45b0a53a-c85a-44cd-ba43-6df62d76befa@tarantool.org> Date: Fri, 24 Nov 2023 15:22:48 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Maksim Kokryashkin , tarantool-patches@dev.tarantool.org, skaplun@tarantool.org, m.kokryashkin@tarantool.org References: <20231122143534.11330-1-max.kokryashkin@gmail.com> <20231122143534.11330-2-max.kokryashkin@gmail.com> In-Reply-To: <20231122143534.11330-2-max.kokryashkin@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD91D460360092162747FECD3F9344D284E44EFE54A97ECC8BA182A05F5380850406492014B31E860B9CFA7A9A37EC374C864A778931E7803581A0C795290F78BFF X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE77BF46084C0059042EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637822A0A225AD602F38638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D88553C0AE89E419C8BE2312C142884DA8117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE9647ADFADE5905B1043FB282AF95FB6BD8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE3F254576263B31EA96136E347CC761E07C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB861051D4BA689FC2E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89FC0F9454058DFE53C6D8C47C27EEC5E9FB5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A54750AE303477A40C2C51AE4376BE166AE5002257AE43D78AF87CCE6106E1FC07E67D4AC08A07B9B0B355ED1E20F5346ACB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF6B7BA2CFFFA5AF27DD563C3EA3D2A9C498459521DC48A1FA1186C2E6ED15FF00A4BD9291AB2A84566E159192F517E6711F8200C84ED327FB87EF584E8A8FBBA5A74DFFEFA5DC0E7F02C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojXb+1cQU8cAOqe2BDanCV4Q== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769B684B529020234F1CFA7A9A37EC374C8C2EB5FBD3A89CC32EBA65886582A37BD66FEC6BF5C9C28D98A98C1125256619760D574B6FC815AB872D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit v3 1/3] Improve error reporting on stack overflow. 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" Hello, Max thanks for the patch! proposed test is passed after reverting a fix On 11/22/23 17:35, Maksim Kokryashkin wrote: > From: Mike Pall > > Thanks to Nicolas Lebedenco. > > (cherry-picked from commit 8135de2a0204e6acd92b231131c4a1e0be03ac1c) > > The `lj_state_growstack` doesn't account for a potential error > handler invocation by `xpcall`, which may lead to the second > error while handling a stack overflow, resulting in a misleading > error "error in error handling", while the real issue is a stack > overflow. This patch addresses this issue by fixing the condition > at which stack overflow errors are thrown. Now it's thrown if the > stack size is at least at the limit, instead of when it is over > the limit. > > This commit also disables the second test from > `lj-603-err-snap-restore`, since after this patch and the two > follow-ups for it, there is no such amount of stack slots with > which the test works the way it should. > > Lastly, this patch adds an alternative to `luacmd` to the > `utils.exec` module, which is called `luabin`. That function is > similar to the `luacmd`, with the only difference of returning > only the executable itself without any additional CLI options > passed. > > Maxim Kokryashkin: > * added the description and the test for the problem > > Part of tarantool/tarantool#9145 > --- > src/lj_state.c | 2 +- > .../lj-603-err-snap-restore.test.lua | 1 + > .../lj-962-stack-overflow-report.test.lua | 10 ++++++++++ > .../lj-962-stack-overflow-report/script.lua | 3 +++ > test/tarantool-tests/utils/exec.lua | 15 ++++++++++++--- > 5 files changed, 27 insertions(+), 4 deletions(-) > create mode 100644 test/tarantool-tests/lj-962-stack-overflow-report.test.lua > create mode 100644 test/tarantool-tests/lj-962-stack-overflow-report/script.lua > > diff --git a/src/lj_state.c b/src/lj_state.c > index 684336d5..76153bad 100644 > --- a/src/lj_state.c > +++ b/src/lj_state.c > @@ -132,7 +132,7 @@ void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need) > n = LJ_STACK_MAX; > } > resizestack(L, n); > - if (L->stacksize > LJ_STACK_MAXEX) > + if (L->stacksize >= LJ_STACK_MAXEX) > lj_err_msg(L, LJ_ERR_STKOV); > } > > diff --git a/test/tarantool-tests/lj-603-err-snap-restore.test.lua b/test/tarantool-tests/lj-603-err-snap-restore.test.lua > index 96ebf92c..f5c8474f 100644 > --- a/test/tarantool-tests/lj-603-err-snap-restore.test.lua > +++ b/test/tarantool-tests/lj-603-err-snap-restore.test.lua > @@ -36,6 +36,7 @@ local function do_test() > -- Tarantool at start, so just skip test for it. > -- luacheck: no global > ['Disable test for Tarantool'] = _TARANTOOL, > + ['Stack overflow is now handled differently'] = true, > }) > > test:ok(not handler_is_called) > diff --git a/test/tarantool-tests/lj-962-stack-overflow-report.test.lua b/test/tarantool-tests/lj-962-stack-overflow-report.test.lua > new file mode 100644 > index 00000000..45a888f4 > --- /dev/null > +++ b/test/tarantool-tests/lj-962-stack-overflow-report.test.lua > @@ -0,0 +1,10 @@ > +local tap = require('tap') > +-- The test reproduces the problem only for GC64 mode with enabled JIT. > +local test = tap.test('lj-962-stack-overflow-report') > +test:plan(1) > + > +local LUABIN = require('utils').exec.luabin(arg) > +local SCRIPT = arg[0]:gsub('%.test%.lua$', '/script.lua') > +local output = io.popen(LUABIN .. ' 2>&1 ' .. SCRIPT, 'r'):read('*all') > +test:like(output, 'stack overflow', 'stack overflow reported correctly') > +test:done(true) > diff --git a/test/tarantool-tests/lj-962-stack-overflow-report/script.lua b/test/tarantool-tests/lj-962-stack-overflow-report/script.lua > new file mode 100644 > index 00000000..31c5ca33 > --- /dev/null > +++ b/test/tarantool-tests/lj-962-stack-overflow-report/script.lua > @@ -0,0 +1,3 @@ > +-- XXX: Function `f` is global to avoid using an additional stack slot. > +-- luacheck: no global > +f = function() f() end; f() > diff --git a/test/tarantool-tests/utils/exec.lua b/test/tarantool-tests/utils/exec.lua > index a56ca2dc..48a08ba5 100644 > --- a/test/tarantool-tests/utils/exec.lua > +++ b/test/tarantool-tests/utils/exec.lua > @@ -1,14 +1,23 @@ > local M = {} > > -function M.luacmd(args) > +local function executable_idx(args) > -- arg[-1] is guaranteed to be not nil. > local idx = -2 > while args[idx] do > assert(type(args[idx]) == 'string', 'Command part have to be a string') > idx = idx - 1 > end > - -- return the full command with flags. > - return table.concat(args, ' ', idx + 1, -1) > + return idx + 1 > +end > + > +function M.luabin(args) > + -- Return only the executable. > + return args[executable_idx(args)] > +end > + > +function M.luacmd(args) > + -- Return the full command with flags. > + return table.concat(args, ' ', executable_idx(args), -1) > end > > local function makeenv(tabenv)