[tarantool-patches] [PATCH] Do not recycle a fiber if it is canceled

Georgy Kirichenko georgy at tarantool.org
Fri Jul 13 14:47:41 MSK 2018


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





More information about the Tarantool-patches mailing list