Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Serge Petrenko <sergepetrenko@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: Re: [PATCH v3] Fix fiber_join() hang in case fiber_cancel() was called
Date: Wed, 6 Feb 2019 17:09:33 +0300	[thread overview]
Message-ID: <20190206140933.ses3gvmayt3u3d4c@esperanza> (raw)
In-Reply-To: <20190206125630.58091-1-sergepetrenko@tarantool.org>

On Wed, Feb 06, 2019 at 03:56:30PM +0300, Serge Petrenko wrote:
> In case a fiber joining another fiber gets cancelled, it stays suspended
> forever and never finishes joining. This happens because fiber_cancel()
> wakes the fiber and removes it from all execution queues.
> Fix this by adding the fiber back to the wakeup queue of the joined
> fiber after each yield.
> 
> Closes #3948
> ---
> https://github.com/tarantool/tarantool/issues/3948
> https://github.com/tarantool/tarantool/tree/sp/gh-3948-fiber-cancel-during-join
> 
> Changes in v3: 
>   - rewrote the test with fiber channel
>     to remove scheduler dependency.
>   - went back to ignoring cancellation
>     till join is complete.
> 
> Changes in v2: 
>   - rewrote the test completely.
>   - instead of continuing to join if the fiber
>     is cancelled make the fiber to be joined
>     non-joinable and exit. This solution was 
>     discussed verbally.
>   - revert comment changes for fiber_yield().
>     It really isn't a cancellation point.
> 
>  src/fiber.c             | 12 ++++++++++--
>  test/app/fiber.result   | 43 +++++++++++++++++++++++++++++++++++++++++
>  test/app/fiber.test.lua | 21 ++++++++++++++++++++
>  3 files changed, 74 insertions(+), 2 deletions(-)
> 
> diff --git a/src/fiber.c b/src/fiber.c
> index 6f3d0ab78..70e992f13 100644
> --- a/src/fiber.c
> +++ b/src/fiber.c
> @@ -392,9 +392,17 @@ fiber_join(struct fiber *fiber)
>  	assert(fiber->flags & FIBER_IS_JOINABLE);
>  
>  	if (! fiber_is_dead(fiber)) {
> -		rlist_add_tail_entry(&fiber->wake, fiber(), state);
> -
>  		do {
> +			/*
> +			 * In case fiber is cancelled during yield
> +			 * it will be remoed from wake queue by a
> +			 * wakeup following the cancel, so we have
> +			 * to put it back in.
> +			 * Having multiple queue entries for the
> +			 * same fiber doesn't hurt, since wakeup
> +			 * is executed only once per fiber.
> +			 */
> +			rlist_add_tail_entry(&fiber->wake, fiber(), state);

I removed the second paragraph of the comment, because it's confusing,
and pushed the patch to 2.1 and 1.10.

      reply	other threads:[~2019-02-06 14:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-06 12:56 Serge Petrenko
2019-02-06 14:09 ` Vladimir Davydov [this message]

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=20190206140933.ses3gvmayt3u3d4c@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=sergepetrenko@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH v3] Fix fiber_join() hang in case fiber_cancel() was called' \
    /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