Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fiber.join() blocks in 'suspended' if fiber has cancelled #3948

Closed
artur-barsegyan opened this issue Jan 25, 2019 · 0 comments
Closed

fiber.join() blocks in 'suspended' if fiber has cancelled #3948

artur-barsegyan opened this issue Jan 25, 2019 · 0 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@artur-barsegyan
Copy link

Bug description: This code leads to "func" fiber remains in a 'suspended' state even after the expected fiber (another_func) has ended.

local fiber = require('fiber')

local tasks = {}

function start(func, name)
    local worker = fiber.create(function()
        local ok, _ = pcall(func)
        fiber.testcancel()
    end)

    tasks[name] = worker
end

function sync_stop(name)
    tasks[name]:cancel()
    while tasks[name] and tasks[name]:status() ~= 'dead' do
        fiber.sleep(1)
    end
end

function another_func()
    fiber.yield()
end

function func()
    local fib = fiber.create(another_func)
    fib:set_joinable(true)
    fib:join()
end

start(func, "test_worker")
sync_stop("test_worker")

Tarantool version: 2.1.1-185-gf583b6c82
OS version: macOS 10.14.1

fiber.info() print grep for 'suspended' fiber:

102:
  csw: 3
  backtrace:
  - C: '#0  0x10e6f5acb in lbox_fiber_join+40'
  - L: join in =[C] at line -1
  - L: (unnamed) in @fiber_bug.lua at line 30
  - C: '#1  0x10e71f595 in lj_BC_FUNCC+68'
  - C: '#2  0x10e72f70f in lua_pcall+155'
  - C: '#3  0x10e6f9b79 in luaT_call+19'
  - C: '#4  0x10e6f6693 in lua_fiber_run_f+87'
  - C: '#5  0x10e64f416 in fiber_cxx_invoke(int (*)(__va_list_tag*), __va_list_tag*)+12'
  - C: '#6  0x10e7072f0 in fiber_loop+42'
  - C: '#7  0x10e826764 in coro_init+75'
  fid: 102
  memory:
    total: 57664
    used: 0
  name: lua 
@kyukhin kyukhin added this to the 2.1.1 milestone Feb 4, 2019
@kyukhin kyukhin added the bug Something isn't working label Feb 4, 2019
sergepetrenko added a commit that referenced this issue Feb 4, 2019
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 ourselves to the joined fibers wake queue on every
iteration. While joining the fiber ignores cancelation.

Also, while we're at it, fix comment for fiber_yield(): it obviously is
a cancellation point.

Closes #3948
@kyukhin kyukhin modified the milestones: 2.1.1, 1.10.3 Feb 4, 2019
sergepetrenko added a commit that referenced this issue Feb 5, 2019
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 handling possible cancellation in fiber_join().

Closes #3948
sergepetrenko added a commit that referenced this issue Feb 6, 2019
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
sergepetrenko added a commit that referenced this issue Feb 6, 2019
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
@locker locker closed this as completed in d69c149 Feb 6, 2019
locker pushed a commit that referenced this issue Feb 6, 2019
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

(cherry picked from commit d69c149)
SudoBobo pushed a commit that referenced this issue Feb 8, 2019
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
@kyukhin kyukhin added the tmp label Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants