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 CFD3D70202; Wed, 24 Feb 2021 13:29:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CFD3D70202 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1614162589; bh=C276ykdF7q8ncmhKIKc5KV6llaob3bmnafq3dTaqbNc=; 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=OWfcR/WdJgBKAI8nR9na62M+wi1bFipOV7FgLRpkm2LAJ82JPGLWj543ffannm58B BY9T2sHYU8238QrAIIZA07t+MMWC79lci4WWz+lnpPmnNfLm4YUIx56WGlTX6wuw1O Oh7OKTWGxC9N03UN9JSdRqbwiNWlTD2ihhcaOTyw= Received: from smtp45.i.mail.ru (smtp45.i.mail.ru [94.100.177.105]) (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 9F11B71828 for ; Wed, 24 Feb 2021 13:27:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9F11B71828 Received: by smtp45.i.mail.ru with esmtpa (envelope-from ) id 1lErOU-0001xX-VG; Wed, 24 Feb 2021 13:27:47 +0300 To: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org, yaroslav.dynnikov@tarantool.org References: Message-ID: <285c9e07-de09-f115-2dfb-5265e10f5716@tarantool.org> Date: Wed, 24 Feb 2021 13:27:46 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD975C3EC174F566922928A658C60196E87DF7449A63D990329182A05F53808504040F74BBF76922D3A561E3B5C614DF43FC0D51F83E20193D9304368CDB87B540E X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B264C8851FD8E810EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006371E4BC0E00C009995EA1F7E6F0F101C674E70A05D1297E1BBC6CDE5D1141D2B1CC8CD956854CCCECAC7F245D6785BBE4593A5A3BCC09CE0DB9FA2833FD35BB23D9E625A9149C048EE26055571C92BF10FF6B57BC7E64490618DEB871D839B7333395957E7521B51C2DFABB839C843B9C08941B15DA834481F8AA50765F7900637A6F6611B2784C7A4389733CBF5DBD5E9B5C8C57E37DE458BD9DD9810294C998ED8FC6C240DEA76428AA50765F79006371EC10726814CC4C8D81D268191BDAD3DBD4B6F7A4D31EC0BEA7A3FFF5B025636D81D268191BDAD3D78DA827A17800CE793D6E5F245F405F3EC76A7562686271EEC990983EF5C032935872C767BF85DA29E625A9149C048EE0A3850AC1BE2E735F67BA0E7924E9B8D4AD6D5ED66289B524E70A05D1297E1BB35872C767BF85DA227C277FBC8AE2E8B38B2F2E9F2BEE38D75ECD9A6C639B01B4E70A05D1297E1BBC6867C52282FAC85D9B7C4F32B44FF57285124B2A10EEC6C00306258E7E6ABB4E4A6367B16DE6309 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24A6D60772A99906F8E1CD14B953EB46DAA8F4A335E31D3A2355D89D7DBCDD132 X-C1DE0DAB: 0D63561A33F958A5D0546E168D2746072BDB2E5570E9B57DED6D216839D0D394D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75B7BFB303F1C7DB4D8E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D346840168BCAD8054EAED5D287E79486C2935DA451E1E29CB7C1C6947CBAD5B2A01FAF9970F4BB9CB41D7E09C32AA3244CDF140F86D3FC9CB7A42AE7152DA221E130363D8B7DA7DD44FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyK6JYJ15DtIB7jDyDvH5Cw== X-Mailru-Sender: 583F1D7ACE8F49BD9317CE1922F30C7E1C53BFB8007E4B78264F5EDAA033FC3CE3336F2033622E3923E75C7104EB1B885DEE61814008E47C7013064206BFB89F93956FB04BA385BE9437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH vshard 06/11] util: introduce fiber_is_self_canceled() 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: Oleg Babin via Tarantool-patches Reply-To: Oleg Babin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for your patch. LGTM. On 23.02.2021 03:15, Vladislav Shpilevoy wrote: > Original fiber.testcancel() has an issue - it is not > exception-safe. This makes it unusable for code which wants to do > cleanup before cancellation. > > The patch introduces util.fiber_is_self_canceled() which checks if > the current fiber is canceled but returns true/false instead of > throwing an error. > > The patch is going to be used in the map-reduce patches where it > will be necessary to check if the fiber is canceled. And if it > is - perform cleanup and quit whatever the code was doing. > > Part of #147 > --- > test/unit/util.result | 28 ++++++++++++++++++++++++++++ > test/unit/util.test.lua | 14 ++++++++++++++ > vshard/util.lua | 8 ++++++++ > 3 files changed, 50 insertions(+) > > diff --git a/test/unit/util.result b/test/unit/util.result > index 679c087..c83e80c 100644 > --- a/test/unit/util.result > +++ b/test/unit/util.result > @@ -266,3 +266,31 @@ assert(type(err) == 'table') > --- > - true > ... > +-- > +-- Exception-safe fiber cancel check. > +-- > +self_is_canceled = util.fiber_is_self_canceled > +--- > +... > +assert(not self_is_canceled()) > +--- > +- true > +... > +ok = nil > +--- > +... > +_ = fiber.create(function() \ > + local f = fiber.self() \ > + pcall(f.cancel, f) \ > + ok = self_is_canceled() \ > +end) > +--- > +... > +test_run:wait_cond(function() return ok ~= nil end) > +--- > +- true > +... > +assert(ok) > +--- > +- true > +... > diff --git a/test/unit/util.test.lua b/test/unit/util.test.lua > index df3db6f..881feb4 100644 > --- a/test/unit/util.test.lua > +++ b/test/unit/util.test.lua > @@ -107,3 +107,17 @@ _ = test_run:wait_cond(function() return ok or err end) > assert(not ok) > err.message > assert(type(err) == 'table') > + > +-- > +-- Exception-safe fiber cancel check. > +-- > +self_is_canceled = util.fiber_is_self_canceled > +assert(not self_is_canceled()) > +ok = nil > +_ = fiber.create(function() \ > + local f = fiber.self() \ > + pcall(f.cancel, f) \ > + ok = self_is_canceled() \ > +end) > +test_run:wait_cond(function() return ok ~= nil end) > +assert(ok) > diff --git a/vshard/util.lua b/vshard/util.lua > index d78f3a5..30a1e6e 100644 > --- a/vshard/util.lua > +++ b/vshard/util.lua > @@ -225,6 +225,13 @@ local function fiber_cond_wait(cond, timeout) > return nil, lerror.make(err) > end > > +-- > +-- Exception-safe way to check if the current fiber is canceled. > +-- > +local function fiber_is_self_canceled() > + return not pcall(fiber.testcancel) > +end > + > return { > tuple_extract_key = tuple_extract_key, > reloadable_fiber_create = reloadable_fiber_create, > @@ -235,4 +242,5 @@ return { > table_copy_yield = table_copy_yield, > table_minus_yield = table_minus_yield, > fiber_cond_wait = fiber_cond_wait, > + fiber_is_self_canceled = fiber_is_self_canceled, > }