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 737D4A022E8; Thu, 1 Feb 2024 14:25:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 737D4A022E8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1706786728; bh=rjNjhoZ3odMZNZ0XrILjdVjwwWkEFMlyC8AAisbzVCg=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=P+8+6FFAFeWu7qqamlfTEQCLRlUfUGSzuClsNnhFr6k7Duk+eX+NMaUN1fyW9phOn 4SF36Nq2/UxPOoL2S9ZyjKKtFReBzAPp757nK1SDDuM8T4dsPqo10/ort5fpYhUs1j 7mOt2qJJ7GSNAXxkKRUqeHju79F+jKgkL42dnCH0= Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 089A6A022E8 for ; Thu, 1 Feb 2024 14:25:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 089A6A022E8 Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2d066b532f0so11869781fa.1 for ; Thu, 01 Feb 2024 03:25:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706786700; x=1707391500; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FNyqmmsK9xes913GaEwLYqx1Rb5PU1RZFa8O4AaZ58M=; b=J84TpFYO8Cywup/YMkf1/y5sj+MiNGGkvseXXANPPbV/vN25NMLJ3m5ELRA4HVCy48 guw7yN1iLeJ/377MYJVcsBXv59HwnESxiB9Nv/qSJSGyXvkf7MknvxmCa3UGRS5LFAUb ZZbCCD4vVOE4sb14ZPcozuMIM//tu1ntexVZ7Dy+vEeydoMUKPt5dzp3OosisKuVYQmH BW8BzaC413kiisUvMLfMPzKeFYcU/UkxDBAdJ2SmEuFLcDlIWG2ag4F88dJ1KEnu5VXf p8fR/XS784n/2DSlvr8UDYUXC2MczKgrGANkcsqS3G4RlT39V1rgYKWTjyH5opYNmBDx MQig== X-Gm-Message-State: AOJu0YyaoIK49PNnreN57+zL+RIRoNWosAtyU1jwX/nbVmar9E35T6lK /lAYvHSjHhkEN2GSHpxwMTBd3ksmE5lt9yEbEC/3gWTLaNPUaYcpTppHTOg9 X-Google-Smtp-Source: AGHT+IHnk1jCJQ+Em9SPMixM2uJRkKlVRzSJ8SvnTfLzs6m4ujy5jaW+rCDBWGKpcG6q9DBgviTaHQ== X-Received: by 2002:a2e:a706:0:b0:2cd:8ce7:71e1 with SMTP id s6-20020a2ea706000000b002cd8ce771e1mr2927716lje.4.1706786700060; Thu, 01 Feb 2024 03:25:00 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWrdJfvtWNNPmlzHMjz3l7joGYSys2yOTzqA0HYhQSSQpGCiGa/zg87njaMsiSZsjfxpTvgnd56MCQkqEf+BJ6jVUDX0Y6CdikPRBh/Cb0i4VPaj3ukZFvapjMPAA== Received: from localhost.localdomain (95-24-0-113.broadband.corbina.ru. [95.24.0.113]) by smtp.gmail.com with ESMTPSA id z9-20020a2e3509000000b002cdf37ee19dsm2372647ljz.7.2024.02.01.03.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 03:24:59 -0800 (PST) X-Google-Original-From: Maxim Kokryashkin To: tarantool-patches@dev.tarantool.org, skaplun@tarantool.org, sergeyb@tarantool.org Date: Thu, 1 Feb 2024 14:24:46 +0300 Message-ID: <602fb56f3231b9344f965c79017392aaf6e9ce83.1706786622.git.m.kokryashkin@tarantool.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit v4 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: Maxim Kokryashkin via Tarantool-patches Reply-To: Maxim Kokryashkin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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) -- 2.43.0