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 203566F3E5; Mon, 8 Nov 2021 13:44:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 203566F3E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636368281; bh=K4IaKw9pEfdNpkITFvUqRqsMaVQkc5UJa6hT2OG4Q08=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=QHepHrq6sMafzcMgHGNcROD4NsG/A/eL+tKfbCoOf+970B1MVRqxUWb4Om4e+Rv4p 82+KYLbQ3vmThge57d5DoUqTIqga8YJZEMmL+RtmNVZCPUTfR92gkjWzfULOjdeL2h RTa6ZNyu5aLcabQsGfSfdTAFQBiYsTCe4sc6yeAY= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id D87846F3E5 for ; Mon, 8 Nov 2021 13:44:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D87846F3E5 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mk28k-0004tQ-RK; Mon, 08 Nov 2021 13:44:39 +0300 Date: Mon, 8 Nov 2021 13:42:51 +0300 To: Igor Munkin Message-ID: References: <20211005102829.30267-1-skaplun@tarantool.org> <20211102160844.GF8831@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211102160844.GF8831@tarantool.org> X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9F9D976862A30D4FE73DAF5629B89E81F7BE3C6ABECA89A3F182A05F5380850406DBAB007113FDE57599E3A2F64F915C63EE945E6ABF0D05C18578AD0B87D6168 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE73C714006C69EB7BAEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374CC1EE7F84E0F1BE8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D80DF29506639EB33AAE9B54723D514BE3117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B68A0907C648FB30DE089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A598E443155A8DD250237B9A574EDC2F7DF8DD3ECFEDB37B94D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA753753CEE10E4ED4A7410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3475AE8838CC1BF58E283C30943F9B8F443FE3A2A90E7960BB3BC50E63FEB693CF036FA2B97520B7B61D7E09C32AA3244C8B44D94709BECD8FD6C96BECF3B558D355E75C8D0ED9F6EEFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj9/1IdNVT2RaFoAROTkiYgA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D7A6A332B4578796CEE60C3090DFFB7560FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED567EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix frame traversal for __gc handler frames. 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 Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Igor, Thanks for the review! On 02.11.21, Igor Munkin wrote: > Sergey, > > Thanks for the patch! Please, consider my comments below. > > On 08.10.21, Sergey Kaplun wrote: > > Hi, Sergos! > > > > Thanks for the review! > > > > > > > > > The new commit message is the following: > > > > | Fix frame traversal for __gc handler frames. > > | > > | Reported by Changochen. > > | > > | (cherry picked from 53f82e6e2e858a0a62fd1a2ff47e9866693382e6) > > | > > | A cframe unwinding is missed for a C protected frame during a search for > > | an error function to handle a runtime error. It leads to undefined > > | behaviour or crash, when raising a runtime error on stack with the CP > > | frame before an error function handler (for example, an error in __gc > > | handler). > > | > > | This patch adds missing unwinding for CP frame. > > | > > | Sergey Kaplun: > > | * added the description and the test for the problem > > > > Branch is force-pushed. > > > > > > > > > > Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-601-fix-gc-finderrfunc > > > > Tarantool branch: https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-fix-gc-finderrfunc > > > > LuaJIT issue: https://github.com/LuaJIT/LuaJIT/issues/601 > > > > > > > > src/lj_err.c | 1 + > > > > .../lj-601-fix-gc-finderrfunc.test.lua | 25 +++++++++++++++++++ > > > > 2 files changed, 26 insertions(+) > > > > create mode 100644 test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua > > > > > > > > > > > diff --git a/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua b/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua > > > > new file mode 100644 > > > > index 00000000..d8d79100 > > > > --- /dev/null > > > > +++ b/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua > > > > > > Unfortunately the test passes on the ’tarantool’ branch > > > > > > s-ostanevich:luajit s.ostanevich$ git checkout tarantool > > > Switched to branch 'tarantool' > > > s-ostanevich:luajit s.ostanevich$ git clean -xdff > > > […] > > > s-ostanevich:luajit s.ostanevich$ cmake . > > > […] > > > s-ostanevich:luajit s.ostanevich$ make > > > […] > > > [100%] Built target libluajit_shared > > > [100%] Built target libluajit > > > [100%] Built target luajit > > > s-ostanevich:luajit s.ostanevich$ git checkout skaplun/lj-601-fix-gc-finderrfunc > > > s-ostanevich:luajit s.ostanevich$ cd test/tarantool-tests > > > s-ostanevich:tarantool-tests s.ostanevich$ ../../src/luajit lj-601-fix-gc-finderrfunc.test.lua > > > TAP version 13 > > > 1..1 > > > ok - successfully collectgarbage with error > > > > Wild guess: it doesn't fail on Mac due to GC64 ;). > > See CI [1] to check my hypothesis. > > Is it possible to fix the test chunk making it check the error even with > GC64 enabled? Yes, may be, but it is hard to forecast its behaviour: We need to generate some garbage on the C stack to be used as an errfunc value from the unprotected C frame suggested as C protected frame (since `cframe_prev()` unwinding is missing for C protected frame (*). (*) I.e. C frames are the following CP|C|CP and during handling the second CP frame in finderrfunc we return the errfunc for the unprotected C frame. > > > > > > > > > > @@ -0,0 +1,25 @@ > > > > +local tap = require('tap') > > > > + > > > > +local test = tap.test('lj-601-fix-gc-finderrfunc') > > > > +test:plan(1) > > > > + > > > > +-- Test file to demonstrate LuaJIT incorrect behaviour, when > > > > +-- throwing error in __gc finalizer. > > > > +-- See also, https://github.com/LuaJIT/LuaJIT/issues/601. > > > > + > > > > +collectgarbage() > > > > + > > > > +local a = newproxy(true) > > > > +getmetatable(a).__gc = function() > > > > + -- Function to raise error via `lj_err_run()` inside __gc. > > What does exactly raise an error in this function? `collectgarbage()` returns number and attemt to call this number raises an error. > > > > > + local _ = load(function() collectgarbage()() end) > > > > +end > > > > + > > > > +-- XXX: Generate a small bunch of proxies. Need several to call > > > > +-- `collectgarbage()` on another proxy inside __gc. N cycles is > > > > +-- empirical number. > > Why do you even need this loop? Why can't you just assign nil to ? We need to create a chain with C|CP frames to use errfunction value (that is garbage) from C frame as it was from C protected frame. Add the corresponding comment. See the iterative patch below. Branch is force-pushed. > > > > > +for _ = 1, 4 do newproxy(a) end > > > > +collectgarbage('collect') > > > > + > > > > +test:ok(true, 'successfully collectgarbage with error') > > Minor: I propose to reword the following way: > | error in __gc is successfully handled Fixed. Side note: 4 cycles is not enough sometimes (test is flaky) -- change them to 6. See no false positives oks after the changes without fix. =================================================================== diff --git a/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua b/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua index d8d79100..38248c5b 100644 --- a/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua +++ b/test/tarantool-tests/lj-601-fix-gc-finderrfunc.test.lua @@ -16,10 +16,12 @@ getmetatable(a).__gc = function() end -- XXX: Generate a small bunch of proxies. Need several to call --- `collectgarbage()` on another proxy inside __gc. N cycles is --- empirical number. -for _ = 1, 4 do newproxy(a) end +-- `collectgarbage()` on another proxy inside __gc to get mix from +-- C and C protected frames (we call `collectgarbage()` that +-- starts finalizer in __gc metamethod which calls +-- `collectgarbage()` again). N cycles is empirical number. +for _ = 1, 6 do newproxy(a) end collectgarbage('collect') -test:ok(true, 'successfully collectgarbage with error') +test:ok(true, 'error in __gc is successfully handled') os.exit(test:check() and 0 or 1) =================================================================== > > > > > +os.exit(test:check() and 0 or 1) > > > > -- > > > > 2.31.0 > > > > > > > > > > > [1]: https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-fix-gc-finderrfunc-no-fix > > > > -- > > Best regards, > > Sergey Kaplun > > -- > Best regards, > IM -- Best regards, Sergey Kaplun