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 B18066EFDE6; Sat, 18 Nov 2023 02:41:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B18066EFDE6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1700264511; bh=h9jHrxQIxPcFxLKCoXAi7Z9kuEMHHGkCRatvNKUves4=; 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=HwOPwh+9Nom3YHAWjIboKGEbixgTVo0VCPjvdNoJF3012NpFh1LQAX/zTGgLzoo5C g8ToeNQi7NrNLGeTL/Vz92t5qXkve1rL7I/YA/RwkEvN561auHjlJ+qcabB6V+GJcI NUudGhbjhJ1399TWGu3p9n7sVfjlnaZKVXgjjpMc= Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 495516EFDE6 for ; Sat, 18 Nov 2023 02:41:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 495516EFDE6 Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-507c1936fd5so3893673e87.1 for ; Fri, 17 Nov 2023 15:41:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700264484; x=1700869284; 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=Xi3r0vSrNdSnx0vismFzsF0xxaRm3oAGv9zmqgOjAE8=; b=Ju1ylOL0B79wyVmXZ+kvMQSvLT+QvPt8ovRoZWQcGuyLrjLGT7bKAI+xcgJzb+Yor+ f6GhSeKkEUeDR8kaZ2eR1sT0VJe0HEgL/Db5CBY9zRPf67pme8PUTKVRZ+S4Q1Va59Ei xq6NzT0+ZxjeeqQnVwcRpNlYHEBwxMTcwrUHKmxJKZngtnD0CrXEFaBVqUmE2DSnkVXp Z0NNsBG5/DXEk0LVKkGy5D2wcmqouN2H4rwA5lgo8IHML2mCrg/QlcD9ulWveVeWtEC9 bnnlCCvX1lEmIqTRYK0voqm741QY1rQGprhgksczNhSdsenoQPtIKFt16sLz7uDzrQuL bEGQ== X-Gm-Message-State: AOJu0Yy6ZNOgNRoSTj/a4fgaXbePa7f3LG9xpAi6SWQrb6PVz8SFcUvw azAO1r3jI4aC+sv+N5c9GsLH3rYDiM2MowvW X-Google-Smtp-Source: AGHT+IGCQshlzpfTEhPFRkPT830y43uJ+YOv844AqZ/J9K4PVZ5lbP/HhCS/Tb+6JCitnA8gUAyDZA== X-Received: by 2002:a05:6512:3da8:b0:509:8e88:2c16 with SMTP id k40-20020a0565123da800b005098e882c16mr3189284lfv.27.1700264484061; Fri, 17 Nov 2023 15:41:24 -0800 (PST) Received: from localhost.localdomain (95-24-0-215.broadband.corbina.ru. [95.24.0.215]) by smtp.gmail.com with ESMTPSA id w14-20020a2e9bce000000b002c83b0bd971sm360587ljj.2.2023.11.17.15.41.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 17 Nov 2023 15:41:23 -0800 (PST) To: tarantool-patches@dev.tarantool.org, sergeyb@tarantool.org, skaplun@tarantool.org, m.kokryashkin@tarantool.org Date: Sat, 18 Nov 2023 02:41:14 +0300 Message-Id: <20231117234116.60037-2-max.kokryashkin@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20231117234116.60037-1-max.kokryashkin@gmail.com> References: <20231117234116.60037-1-max.kokryashkin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit 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: Maksim Kokryashkin via Tarantool-patches Reply-To: Maksim 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. 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 | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/tarantool-tests/lj-962-stack-overflow-report.test.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..bcddff01 --- /dev/null +++ b/test/tarantool-tests/lj-962-stack-overflow-report.test.lua @@ -0,0 +1,24 @@ +local tap = require('tap') +local test = tap.test('lj-962-stack-overflow-report') + +test:plan(2) + +-- luacheck: no unused +local _, _, _, _, _, _, _ +local error_message +local handler_is_called = false +local function errfunc(err) + -- luacheck: no unused + local _ + error_message = err + handler_is_called = true +end + +local function recursive_f() + recursive_f() +end +xpcall(recursive_f, errfunc) + +test:ok(handler_is_called, 'error handler was able to use a stack slot') +test:like(error_message, '.+stack overflow$', 'stack overflow happened') +test:done(true) -- 2.39.3 (Apple Git-145)