From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Georgy Kirichenko Subject: Re: [PATCH] box: serialize calls to box.cfg Date: Tue, 07 Aug 2018 14:26:49 +0300 Message-ID: <2423915.YWta1rXLNJ@localhost> In-Reply-To: <20180807110901.z3thcmcwkt3qkyrm@esperanza> References: <619fdb85de8edff29334abcf75ffec7aa8647723.1533634796.git.vdavydov.dev@gmail.com> <20180807110901.z3thcmcwkt3qkyrm@esperanza> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart17244453.eO6LH54R9O"; micalg="pgp-sha256"; protocol="application/pgp-signature" To: Vladimir Davydov Cc: tarantool-patches@freelists.org List-ID: --nextPart17244453.eO6LH54R9O Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Looks good to me On Tuesday, August 7, 2018 2:09:01 PM MSK Vladimir Davydov wrote: > On Tue, Aug 07, 2018 at 12:43:26PM +0300, Vladimir Davydov wrote: > > It is dangerous to call box.cfg() concurrently from different fibers. > > For example, replication configuration uses static variables and yields > > so calling it concurrently can result in a crash. To make sure it never > > happens, let's protect box.cfg() with a lock. > > > > Closes #3606 > > --- > > https://github.com/tarantool/tarantool/issues/3606 > > https://github.com/tarantool/tarantool/tree/dv/gh-3606-concurrent-replicat > > ion-cfg-fix> > > src/box/lua/load_cfg.lua | 21 ++++++++++++++++++--- > > test/replication/misc.result | 24 ++++++++++++++++++++++++ > > test/replication/misc.test.lua | 10 ++++++++++ > > 3 files changed, 52 insertions(+), 3 deletions(-) > > > > diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua > > index 0b668cdc..4de79220 100644 > > --- a/src/box/lua/load_cfg.lua > > +++ b/src/box/lua/load_cfg.lua > > @@ -5,6 +5,21 @@ local json = require('json') > > > > local private = require('box.internal') > > local urilib = require('uri') > > local math = require('math') > > > > +local fiber = require('fiber') > > + > > +-- Function decorator that is used to prevent box.cfg() from > > +-- being called concurrently by different fibers. > > +local lock = fiber.channel(1) > > +local function locked(f) > > + return function(...) > > + lock:put(true) > > + local status = pcall(f, ...) > > + lock:get() > > + if not status then > > + box.error() > > + end > > + end > > +end > > Georgy noted that we'd better use error() to re-throw the error returned > by box.cfg(). Updated on the branch, the incremental diff is below: > > diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua > index 4de79220..c68a3583 100644 > --- a/src/box/lua/load_cfg.lua > +++ b/src/box/lua/load_cfg.lua > @@ -13,10 +13,10 @@ local lock = fiber.channel(1) > local function locked(f) > return function(...) > lock:put(true) > - local status = pcall(f, ...) > + local status, err = pcall(f, ...) > lock:get() > if not status then > - box.error() > + error(err) > end > end > end --nextPart17244453.eO6LH54R9O Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEFZT35EtIMRTDS5hJnoTdFFzh6LUFAltpgfkACgkQnoTdFFzh 6LXB6AgAt5KI/lDn9+PYn3rbpuHSNUZzKA8SZyLSVypZ9N3KtDgQgc8ijnl3HCv3 E6DUWYaKVs49kpvPASHsn73ZKiXcwWDLfnwBjOv5LHZ/TG7cHoOnfDyNop9zeRqn 3TquNkvZMZJ62/IFO2PSZjVGvGzzR6DumjAugbJwuHIoNhTpu9q5yyeLkwc3zoFd LRwrCT+B6vqy0Xx+cXZwWS2JtRDBvQzsPXvHVmE4jgPOWJQj3F0Kiu/Fl2i7D+wt Poc28Hj4VhRCfZ8WnN7qlZcsKiDZ8+Nj2oS8oLVQ9E6uELC9JU5RIXiR1gniKCTt RPFlHxJWQx3pykEZLmKikmTEXCrJvQ== =WPtw -----END PGP SIGNATURE----- --nextPart17244453.eO6LH54R9O--