Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: properly handle fiber cancellation for fiber.cond
Before this patch fiber.cond():wait() just returns for cancelled fiber. In contrast fiber.channel():get() threw "fiber is canceled" error. This patch unify behaviour of channels and condvars and also fixes related net.box module problem - it was impossible to interrupt net.box call with fiber.cancel because it used fiber.cond under the hood. Test cases for both bugs are added. Closes #4834 Closes #5013 @TarantoolBot document Title: fiber.cond():wait() throws if fiber is cancelled Currently fiber.cond():wait() throws an error if waiting fiber is cancelled like in case with fiber.channel():get().
- Loading branch information
Showing
5 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-- test-run result file version 2 | ||
fiber = require('fiber') | ||
| --- | ||
| ... | ||
test_run = require('test_run').new() | ||
| --- | ||
| ... | ||
|
||
err = nil | ||
| --- | ||
| ... | ||
|
||
test_run:cmd("setopt delimiter ';'") | ||
| --- | ||
| - true | ||
| ... | ||
function test() | ||
_, err = pcall(function() fiber.cond():wait() end) | ||
end; | ||
| --- | ||
| ... | ||
test_run:cmd("setopt delimiter ''"); | ||
| --- | ||
| - true | ||
| ... | ||
|
||
f = fiber.new(test) | ||
| --- | ||
| ... | ||
fiber.yield() | ||
| --- | ||
| ... | ||
f:cancel() | ||
| --- | ||
| ... | ||
fiber.yield() | ||
| --- | ||
| ... | ||
f | ||
| --- | ||
| - the fiber is dead | ||
| ... | ||
err | ||
| --- | ||
| - fiber is cancelled | ||
| ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
fiber = require('fiber') | ||
test_run = require('test_run').new() | ||
|
||
err = nil | ||
|
||
test_run:cmd("setopt delimiter ';'") | ||
function test() | ||
_, err = pcall(function() fiber.cond():wait() end) | ||
end; | ||
test_run:cmd("setopt delimiter ''"); | ||
|
||
f = fiber.new(test) | ||
fiber.yield() | ||
f:cancel() | ||
fiber.yield() | ||
f | ||
err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
-- test-run result file version 2 | ||
remote = require 'net.box' | ||
| --- | ||
| ... | ||
fiber = require 'fiber' | ||
| --- | ||
| ... | ||
test_run = require('test_run').new() | ||
| --- | ||
| ... | ||
|
||
-- #4834: Cancelling fiber doesn't interrupt netbox operations | ||
function infinite_call() fiber.channel(1):get() end | ||
| --- | ||
| ... | ||
box.schema.func.create('infinite_call') | ||
| --- | ||
| ... | ||
box.schema.user.grant('guest', 'execute', 'function', 'infinite_call') | ||
| --- | ||
| ... | ||
|
||
error_msg = nil | ||
| --- | ||
| ... | ||
test_run:cmd("setopt delimiter ';'") | ||
| --- | ||
| - true | ||
| ... | ||
function gh4834() | ||
local cn = remote.connect(box.cfg.listen) | ||
local f = fiber.new(function() | ||
_, error_msg = pcall(cn.call, cn, 'infinite_call') | ||
end) | ||
f:set_joinable(true) | ||
fiber.yield() | ||
f:cancel() | ||
f:join() | ||
cn:close() | ||
end; | ||
| --- | ||
| ... | ||
test_run:cmd("setopt delimiter ''"); | ||
| --- | ||
| - true | ||
| ... | ||
gh4834() | ||
| --- | ||
| ... | ||
error_msg | ||
| --- | ||
| - fiber is cancelled | ||
| ... | ||
box.schema.func.drop('infinite_call') | ||
| --- | ||
| ... | ||
infinite_call = nil | ||
| --- | ||
| ... | ||
channel = nil | ||
| --- | ||
| ... | ||
error_msg = nil | ||
| --- | ||
| ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
remote = require 'net.box' | ||
fiber = require 'fiber' | ||
test_run = require('test_run').new() | ||
|
||
-- #4834: Cancelling fiber doesn't interrupt netbox operations | ||
function infinite_call() fiber.channel(1):get() end | ||
box.schema.func.create('infinite_call') | ||
box.schema.user.grant('guest', 'execute', 'function', 'infinite_call') | ||
|
||
error_msg = nil | ||
test_run:cmd("setopt delimiter ';'") | ||
function gh4834() | ||
local cn = remote.connect(box.cfg.listen) | ||
local f = fiber.new(function() | ||
_, error_msg = pcall(cn.call, cn, 'infinite_call') | ||
end) | ||
f:set_joinable(true) | ||
fiber.yield() | ||
f:cancel() | ||
f:join() | ||
cn:close() | ||
end; | ||
test_run:cmd("setopt delimiter ''"); | ||
gh4834() | ||
error_msg | ||
box.schema.func.drop('infinite_call') | ||
infinite_call = nil | ||
channel = nil | ||
error_msg = nil |