[PATCH v3] Fix fiber_join() hang in case fiber_cancel() was called

Vladimir Davydov vdavydov.dev at gmail.com
Wed Feb 6 17:09:33 MSK 2019


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.



More information about the Tarantool-patches mailing list