From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 3280E26E92 for ; Fri, 13 Jul 2018 07:47:46 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sxs09TnOl37y for ; Fri, 13 Jul 2018 07:47:46 -0400 (EDT) Received: from smtp34.i.mail.ru (smtp34.i.mail.ru [94.100.177.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id DF38F26E7E for ; Fri, 13 Jul 2018 07:47:45 -0400 (EDT) From: Georgy Kirichenko Subject: [tarantool-patches] [PATCH] Do not recycle a fiber if it is canceled Date: Fri, 13 Jul 2018 14:47:41 +0300 Message-Id: <792cd653673e62d847222fb0ec53d8a6170aa8c9.1531481944.git.georgy@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Georgy Kirichenko If a fiber pool reuses already canceled fiber then the fiber reports an error for any next request. Now canceled fiber returns and fiber pool creates a new one. Fixes #3527 --- Issue: https://github.com/tarantool/tarantool/3527 Branch: https://github.com/tarantool/tarantool/tree/gh-3527-fiber-is-cancelled-in-pool src/fiber_pool.c | 6 +++--- test/app/fiber.result | 18 ++++++++++++++++++ test/app/fiber.test.lua | 6 ++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/fiber_pool.c b/src/fiber_pool.c index aa8b19510..d132789d3 100644 --- a/src/fiber_pool.c +++ b/src/fiber_pool.c @@ -46,7 +46,7 @@ fiber_pool_f(va_list ap) pool->size++; restart: msg = NULL; - while (! stailq_empty(output)) { + while (!stailq_empty(output) && !fiber_is_cancelled(fiber())) { msg = stailq_shift_entry(output, struct cmsg, fifo); if (f->caller == &cord->sched && ! stailq_empty(output) && @@ -64,8 +64,8 @@ restart: cmsg_deliver(msg); } /** Put the current fiber into a fiber cache. */ - if (msg != NULL || - ev_monotonic_now(loop) - last_active_at < pool->idle_timeout) { + if (!fiber_is_cancelled(fiber()) && (msg != NULL || + ev_monotonic_now(loop) - last_active_at < pool->idle_timeout)) { if (msg != NULL) last_active_at = ev_monotonic_now(loop); /* diff --git a/test/app/fiber.result b/test/app/fiber.result index 0253fe08f..9eedc6e95 100644 --- a/test/app/fiber.result +++ b/test/app/fiber.result @@ -1209,3 +1209,21 @@ test_run:cmd("clear filter") --- - true ... +box.schema.user.grant('guest', 'execute', 'universe') +--- +... +con = require('net.box').connect(box.cfg.listen) +--- +... +pcall(con.eval, con, 'fiber.cancel(fiber.self())') +--- +- false +- fiber is cancelled +... +con:eval('fiber.sleep(0) return "Ok"') +--- +- Ok +... +box.schema.user.revoke('guest', 'execute', 'universe') +--- +... diff --git a/test/app/fiber.test.lua b/test/app/fiber.test.lua index c06a41779..d59cf64ed 100644 --- a/test/app/fiber.test.lua +++ b/test/app/fiber.test.lua @@ -505,3 +505,9 @@ l1 = nil -- cleanup test_run:cmd("clear filter") + +box.schema.user.grant('guest', 'execute', 'universe') +con = require('net.box').connect(box.cfg.listen) +pcall(con.eval, con, 'fiber.cancel(fiber.self())') +con:eval('fiber.sleep(0) return "Ok"') +box.schema.user.revoke('guest', 'execute', 'universe') -- 2.18.0