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 E23336F865; Thu, 29 Apr 2021 00:16:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E23336F865 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1619644584; bh=n5m7Y0AmDEQs5WQf5C6sGWuNe9xZ3wQVFSlfFIcYorA=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=wNTAev/d2EVqge9rUplHFYc0SE0d1i3JosZKOo1VlQ4xBkF0YMgzTsX3qIpmvV3Rm g3drOwk/HBLRVFAVZ8o0iyED4pp9PH083/4L1drsFUrJp5fH/0GAAYW+WS77U+6v2Q 9YbztPLS/VaOpQ+5DwnUotIWDE0YYa5W+58GoeIQ= Received: from smtp17.mail.ru (smtp17.mail.ru [94.100.176.154]) (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 D55366F865 for ; Thu, 29 Apr 2021 00:16:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D55366F865 Received: by smtp17.mail.ru with esmtpa (envelope-from ) id 1lbrXh-0007xA-7E; Thu, 29 Apr 2021 00:16:21 +0300 To: Cyrill Gorcunov , tml References: <20210428102251.552976-1-gorcunov@gmail.com> <20210428102251.552976-3-gorcunov@gmail.com> Message-ID: Date: Wed, 28 Apr 2021 23:16:20 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210428102251.552976-3-gorcunov@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9ECFD8CE5F059401082903BCA05D22506BBA2EDD66B931DE4182A05F53808504047C70DA049FAF85FAE455BA800D6399113C0CFEEBFE829B2014C54FF4B30FA2C X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE78981306C6E927004EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006376F127A835590024F8F08D7030A58E5ADC58D69EE07B14084F39EFFDF887939037866D6147AF826D827E8782C1C90E929A6144F3A46F03EF4117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD182CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE4B6963042765DA4BE45489B29CB19804D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE3A7DFDF579AB090EF2D242C3BD2E3F4C6C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F79006371F24DFF1B2961425731C566533BA786AA5CC5B56E945C8DA X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824A2A04A2ABAA09D25379311020FFC8D4AD65E1E0D8E75882BFD40138DC97EE3BD8 X-C1DE0DAB: 0D63561A33F958A52D62E37D439D2453F22A336A473B14D48F87095F8A31B74FD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D346EDE9E12965E8CD5E781B5E9A6307BE933FFF60992C18FFA6A77B452D508E9FF51D8A50E6F5888CD1D7E09C32AA3244C629C3E8F48F50554F9210F42276677DFF522A1CF68F4BE05927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojoCaqxM2e5so8mK23cNl71Q== X-Mailru-Sender: 504CC1E875BF3E7D9BC0E5172ADA31101247C9DED48D2A51A896FB1093B90585886EBE8F1D453EFD07784C02288277CA03E0582D3806FB6A5317862B1921BA260ED6CFD6382C13A6112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 2/2] fiber: fiber_join -- don't crash on misuse 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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" > diff --git a/src/lua/fiber.c b/src/lua/fiber.c > index 02ec3d158..0c8238cab 100644 > --- a/src/lua/fiber.c > +++ b/src/lua/fiber.c > @@ -791,9 +793,11 @@ lbox_fiber_join(struct lua_State *L) > int num_ret = 0; > int coro_ref = 0; > > - if (!(fiber->flags & FIBER_IS_JOINABLE)) > - luaL_error(L, "the fiber is not joinable"); > - fiber_join(fiber); > + if (fiber_join(fiber) != 0) { > + e = diag_last_error(&fiber()->diag); > + if (e->type == &type_IllegalParams) > + luaL_error(L, e->errmsg); After looking at this hunk I realized that it might be wrong to allow to call join on a non-joinable fiber. Firstly, you have no way to check why did join return -1: because it wasn't joinable or because this is what the fiber's function has returned. It is simply impossible in the public API (module.h). Secondly, fiber_join() is documented to always return the fiber's function result. I see it in module.h and on the site. Here the behaviour has kind of changed - it might return something even if the fiber didn't really end. This is especially bad if the fiber was using some resources which are freed right after the join. And doubly-bad if the user's function never fails, so fiber_join() result wasn't even checked in his code. Thirdly, this leads to inconsistent behaviour. In this example fiber.join does not raise an error - it returns false + error: fiber = require('fiber') do f = fiber.new(function() box.error('other error') end) f:set_joinable(true) end tarantool> f:join() --- - false - '[string "do..."]:2: box.error(): bad arguments' ... But when I change the error type, it raises the error: fiber = require('fiber') do f = fiber.new(function() box.lib.load() end) f:set_joinable(true) end tarantool> f:join() --- - error: Expects box.lib.load('name') but no name passed ... It didn't happen before your patch. The same problem exists for fiber_join_timeout(), but at least it is documented to be able to return before the fiber has joined. With that said, I think we must call panic() on an attempt to join a non-joinable fiber. For easier usage we might need to introduce fiber_join_ex(), which wouldn't mix its own fail and the fiber's function fail. But maybe not now since nobody really asked for that.