diff --git a/src/box/vinyl.c b/src/box/vinyl.c index 9428e934ad231ec22f9d86b76683225be76133bf..41918beba10dd5797722cf8dc212c23046db0653 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -3984,7 +3984,14 @@ vinyl_index_get(struct index *index, const char *key, return -1; } - if (vy_get_by_raw_key(lsm, tx, rv, key, part_count, ret) != 0) + /* + * Make sure the LSM tree isn't deleted while we are + * reading from it. + */ + vy_lsm_ref(lsm); + int rc = vy_get_by_raw_key(lsm, tx, rv, key, part_count, ret); + vy_lsm_unref(lsm); + if (rc != 0) return -1; if (*ret != NULL) { tuple_bless(*ret); diff --git a/test/vinyl/errinj_ddl.result b/test/vinyl/errinj_ddl.result index 7bee4efdcf0a1779733181cf4d999b6cdecf90b9..dcbf90f78f43df9255afbb34616fa68d995382ce 100644 --- a/test/vinyl/errinj_ddl.result +++ b/test/vinyl/errinj_ddl.result @@ -894,6 +894,55 @@ s.index.secondary:select() s:drop() --- ... +-- +-- gh-4109: crash if space is dropped while space.get is reading from it. +-- +s = box.schema.space.create('test', {engine = 'vinyl'}) +--- +... +_ = s:create_index('primary') +--- +... +s:replace{1} +--- +- [1] +... +box.snapshot() +--- +- ok +... +test_run:cmd("setopt delimiter ';'") +--- +- true +... +box.error.injection.set('ERRINJ_VY_READ_PAGE_TIMEOUT', 0.01); +--- +- ok +... +ch = fiber.channel(1); +--- +... +_ = fiber.create(function() + local _, ret = pcall(s.get, s, 1) + ch:put(ret) +end); +--- +... +s:drop(); +--- +... +ch:get(); +--- +- [1] +... +box.error.injection.set('ERRINJ_VY_READ_PAGE_TIMEOUT', 0); +--- +- ok +... +test_run:cmd("setopt delimiter ''"); +--- +- true +... box.cfg{vinyl_cache = default_vinyl_cache} --- ... diff --git a/test/vinyl/errinj_ddl.test.lua b/test/vinyl/errinj_ddl.test.lua index 52d9de65596edfdd931c6a745af1ccff34329ebd..6413c352ebb113a57556e18c043b739a1a5b097e 100644 --- a/test/vinyl/errinj_ddl.test.lua +++ b/test/vinyl/errinj_ddl.test.lua @@ -395,4 +395,24 @@ s.index.primary:select() s.index.secondary:select() s:drop() +-- +-- gh-4109: crash if space is dropped while space.get is reading from it. +-- +s = box.schema.space.create('test', {engine = 'vinyl'}) +_ = s:create_index('primary') +s:replace{1} +box.snapshot() + +test_run:cmd("setopt delimiter ';'") +box.error.injection.set('ERRINJ_VY_READ_PAGE_TIMEOUT', 0.01); +ch = fiber.channel(1); +_ = fiber.create(function() + local _, ret = pcall(s.get, s, 1) + ch:put(ret) +end); +s:drop(); +ch:get(); +box.error.injection.set('ERRINJ_VY_READ_PAGE_TIMEOUT', 0); +test_run:cmd("setopt delimiter ''"); + box.cfg{vinyl_cache = default_vinyl_cache}