Tarantool development patches archive
 help / color / mirror / Atom feed
From: Georgy Kirichenko <georgy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Georgy Kirichenko <georgy@tarantool.org>
Subject: [tarantool-patches] [PATCH] Do not recycle a fiber if it is canceled
Date: Fri, 13 Jul 2018 14:47:41 +0300	[thread overview]
Message-ID: <792cd653673e62d847222fb0ec53d8a6170aa8c9.1531481944.git.georgy@tarantool.org> (raw)

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

             reply	other threads:[~2018-07-13 11:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-13 11:47 Georgy Kirichenko [this message]
2018-07-16 10:20 ` Vladimir Davydov
2018-07-16 14:57 ` [tarantool-patches] " Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=792cd653673e62d847222fb0ec53d8a6170aa8c9.1531481944.git.georgy@tarantool.org \
    --to=georgy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH] Do not recycle a fiber if it is canceled' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox