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 9787C6DC4B6; Thu, 9 Nov 2023 15:03:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9787C6DC4B6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1699531429; bh=uBfFaDQiveaJXD8SPo+RrRihO92T7RAguzV80IhKd50=; 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=Px/hDiaUP0NWAN2IOq8WKFaf1D7B9q+ljG2lNJoTSxxl3al/NfJ+XLExUT5ER75wS CWFK0RSOyuyjTxVQcZocLU1iJ1Di8y/M6dEGwXTMoQyOnWu5FZd7mtXga3VkX3QkPf KXfxFLuHaad4SJUrZXd8UcSDopgtFHp0hFmr+bjw= Received: from smtp49.i.mail.ru (smtp49.i.mail.ru [95.163.41.91]) (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 8ECB3404481 for ; Thu, 9 Nov 2023 15:03:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8ECB3404481 Received: by smtp49.i.mail.ru with esmtpa (envelope-from ) id 1r13lD-00FPel-0D; Thu, 09 Nov 2023 15:03:47 +0300 Content-Type: multipart/alternative; boundary="------------jw08UnyW0eryLZP68bkHwvy8" Message-ID: Date: Thu, 9 Nov 2023 15:03:46 +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: <20231107210616.53138-1-max.kokryashkin@gmail.com> <20231107210616.53138-2-max.kokryashkin@gmail.com> In-Reply-To: <20231107210616.53138-2-max.kokryashkin@gmail.com> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9C2A6B03AB739174C47D15B14F69B7F1F755FB3122EBF24DD00894C459B0CD1B982760327A65D98401E5435C4B3A1D27BABF1E31C62EE0BEB450968D14EBE582C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79683A3C835791080EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006376AEB812070489DF38638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8F10BD8CC2BF960CCD3DBC635F2AEEE6D117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18BDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE9647ADFADE5905B17C6FCE95544A9834D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE3632EDEA9CD5989A36E0066C2D8992A16C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947C062BEEFFB5F8EA3E2E808ACE2090B5E1725E5C173C3A84C317B107DEF921CE79089D37D7C0E48F6C8AA50765F7900637E6CFFF7AFAFA3B44EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A573CA58BEAEF41FC866F6E889063C7568D50A6C4727D14192F87CCE6106E1FC07E67D4AC08A07B9B00A6B3CD6EB70C818BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF901F76FE306CFDED147E4983AE80FC1D87B71D9B501AE77CFFA3CBBE2B57441C212E5196DFD6A13FD0DB820CB2E38D8B962DC282E8176FD51FD24C0953A00437A74DFFEFA5DC0E7F02C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojKdAcnY08CHK6KvJuzMghRw== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769E1433B3B5C0174CE41D97522F5AC7546DDEE725E12766E67EBA65886582A37BD66FEC6BF5C9C28D98A98C1125256619760D574B6FC815AB872D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit v2 1/2] Print errors from __gc finalizers instead of rethrowing them. 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. --------------jw08UnyW0eryLZP68bkHwvy8 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Max Thanks for the patch! LGTM See my comments below. Sergey On 11/8/23 00:06, Maksim Kokryashkin wrote: > diff --git a/test/tarantool-tests/lj-946-print-errors-from-gc-fin-custom.test.lua b/test/tarantool-tests/lj-946-print-errors-from-gc-fin-custom.test.lua > new file mode 100644 > index 00000000..71efc260 > --- /dev/null > +++ b/test/tarantool-tests/lj-946-print-errors-from-gc-fin-custom.test.lua > @@ -0,0 +1,42 @@ > +local tap = require('tap') > +local test = tap.test('lj-946-print-errors-from-gc-fin-custom'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +test:plan(2) > + > +local ffi = require('ffi') > +local error_in_finalizer = false > + > +local function errfin_handler() > + error_in_finalizer = true > +end > + > +local function new_bad_cdata() > + return ffi.gc(ffi.new('char [?]', 1024), 'uncallable string') > +end > + > +local function test_f() > + collectgarbage('collect') > + -- Make GC aggressive enough to end the atomic phase before > + -- exiting the trace. > + collectgarbage('setstepmul', 400) > + -- The number of iterations is empirical, just big enough for the > + -- issue to strike. > + for _ = 1, 4000 do Works fine with a number of iterations equal to 300, checked locally by running test 1000 times. > + new_bad_cdata() > + end > +end > + > +jit.opt.start('hotloop=1') > +-- Handler is registered but never called before the patch. > +-- It should be called after the patch. > +jit.attach(errfin_handler, 'errfin') > +local status = pcall(test_f) > +-- We have to stop GC now because any step raises the error due to > +-- cursed cdata objects. > +collectgarbage('stop') > +test:ok(status, 'test function completed successfully') > +test:ok(error_in_finalizer, 'error handler called') > + > +test:done(true) > diff --git a/test/tarantool-tests/lj-946-print-errors-from-gc-fin-default.test.lua b/test/tarantool-tests/lj-946-print-errors-from-gc-fin-default.test.lua > new file mode 100644 > index 00000000..dfef11e5 > --- /dev/null > +++ b/test/tarantool-tests/lj-946-print-errors-from-gc-fin-default.test.lua > @@ -0,0 +1,11 @@ > +local tap = require('tap') > +local test = tap.test('lj-flush-on-trace'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +test:plan(1) > + > +local script = require('utils').exec.makecmd(arg, { redirect = '2>&1' }) > +local output = script() > +test:like(output, '.*ERROR in finalizer:.*') testcase description is missed: TAP version 13 1..1 ok - nil > +test:done(true) > diff --git a/test/tarantool-tests/lj-946-print-errors-from-gc-fin-default/script.lua b/test/tarantool-tests/lj-946-print-errors-from-gc-fin-default/script.lua > new file mode 100644 > index 00000000..fdd9ced1 > --- /dev/null > +++ b/test/tarantool-tests/lj-946-print-errors-from-gc-fin-default/script.lua > @@ -0,0 +1,24 @@ > +local ffi = require('ffi') > + > +local function new_bad_cdata() > + return ffi.gc(ffi.new('char [?]', 1024), 'uncallable string') > +end > + > +local function test_f() > + collectgarbage('collect') > + -- Make GC aggressive enough to end the atomic phase before > + -- exiting the trace. > + collectgarbage('setstepmul', 400) > + -- The number of iterations is empirical, just big enough for the > + -- issue to strike. > + for _ = 1, 4000 do > + new_bad_cdata() > + end > +end > + > +jit.opt.start('hotloop=1') > +local status = pcall(test_f) > +-- We have to stop GC now because any step raises the error due to > +-- cursed cdata objects. > +collectgarbage('stop') > +assert(status, 'error is not rethrown') > -- > 2.39.3 (Apple Git-145) > --------------jw08UnyW0eryLZP68bkHwvy8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hi, Max


Thanks for the patch! LGTM

See my comments below.

Sergey

On 11/8/23 00:06, Maksim Kokryashkin wrote:


<snipped>

diff --git a/test/tarantool-tests/lj-946-print-errors-from-gc-fin-custom.test.lua b/test/tarantool-tests/lj-946-print-errors-from-gc-fin-custom.test.lua
new file mode 100644
index 00000000..71efc260
--- /dev/null
+++ b/test/tarantool-tests/lj-946-print-errors-from-gc-fin-custom.test.lua
@@ -0,0 +1,42 @@
+local tap = require('tap')
+local test = tap.test('lj-946-print-errors-from-gc-fin-custom'):skipcond({
+  ['Test requires JIT enabled'] = not jit.status(),
+})
+
+test:plan(2)
+
+local ffi = require('ffi')
+local error_in_finalizer = false
+
+local function errfin_handler()
+    error_in_finalizer = true
+end
+
+local function new_bad_cdata()
+  return ffi.gc(ffi.new('char [?]', 1024), 'uncallable string')
+end
+
+local function test_f()
+  collectgarbage('collect')
+  -- Make GC aggressive enough to end the atomic phase before
+  -- exiting the trace.
+  collectgarbage('setstepmul', 400)
+  -- The number of iterations is empirical, just big enough for the
+  -- issue to strike.
+  for _ = 1, 4000 do

Works fine with a number of iterations equal to 300,

checked locally by running test 1000 times.

+    new_bad_cdata()
+  end
+end
+
+jit.opt.start('hotloop=1')
+-- Handler is registered but never called before the patch.
+-- It should be called after the patch.
+jit.attach(errfin_handler, 'errfin')
+local status = pcall(test_f)
+-- We have to stop GC now because any step raises the error due to
+-- cursed cdata objects.
+collectgarbage('stop')
+test:ok(status, 'test function completed successfully')
+test:ok(error_in_finalizer, 'error handler called')
+
+test:done(true)
diff --git a/test/tarantool-tests/lj-946-print-errors-from-gc-fin-default.test.lua b/test/tarantool-tests/lj-946-print-errors-from-gc-fin-default.test.lua
new file mode 100644
index 00000000..dfef11e5
--- /dev/null
+++ b/test/tarantool-tests/lj-946-print-errors-from-gc-fin-default.test.lua
@@ -0,0 +1,11 @@
+local tap = require('tap')
+local test = tap.test('lj-flush-on-trace'):skipcond({
+  ['Test requires JIT enabled'] = not jit.status(),
+})
+
+test:plan(1)
+
+local script = require('utils').exec.makecmd(arg, { redirect = '2>&1' })
+local output = script()
+test:like(output, '.*ERROR in finalizer:.*')

testcase description is missed:


TAP version 13
1..1
ok - nil

+test:done(true)
diff --git a/test/tarantool-tests/lj-946-print-errors-from-gc-fin-default/script.lua b/test/tarantool-tests/lj-946-print-errors-from-gc-fin-default/script.lua
new file mode 100644
index 00000000..fdd9ced1
--- /dev/null
+++ b/test/tarantool-tests/lj-946-print-errors-from-gc-fin-default/script.lua
@@ -0,0 +1,24 @@
+local ffi = require('ffi')
+
+local function new_bad_cdata()
+  return ffi.gc(ffi.new('char [?]', 1024), 'uncallable string')
+end
+
+local function test_f()
+  collectgarbage('collect')
+  -- Make GC aggressive enough to end the atomic phase before
+  -- exiting the trace.
+  collectgarbage('setstepmul', 400)
+  -- The number of iterations is empirical, just big enough for the
+  -- issue to strike.
+  for _ = 1, 4000 do
+    new_bad_cdata()
+  end
+end
+
+jit.opt.start('hotloop=1')
+local status = pcall(test_f)
+-- We have to stop GC now because any step raises the error due to
+-- cursed cdata objects.
+collectgarbage('stop')
+assert(status, 'error is not rethrown')
--
2.39.3 (Apple Git-145)

--------------jw08UnyW0eryLZP68bkHwvy8--