-
Notifications
You must be signed in to change notification settings - Fork 54
Fix task release in session disconnect #107
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,98 @@ | ||
#!/usr/bin/env tarantool | ||
|
||
local fiber = require('fiber') | ||
local netbox = require('net.box') | ||
local os = require('os') | ||
local queue = require('queue') | ||
local tap = require('tap') | ||
local tnt = require('t.tnt') | ||
|
||
local tube | ||
local test = tap.test('lost a session id after yield') | ||
|
||
-- The test cases are in check_result(). | ||
test:plan(2) | ||
|
||
-- Verify that _queue_taken space is empty. | ||
local function check_result() | ||
if tube == nil then | ||
os.exit(1) | ||
end | ||
|
||
-- tube:drop() is most simple way to check that _queue_taken | ||
-- is empty. It give an error if it is not so. | ||
local ok, res = pcall(tube.drop, tube) | ||
test:is(ok, true, 'drop empty queue') | ||
test:is(res, true, 'tube:drop() result is true') | ||
|
||
tnt.finish() | ||
os.exit(test:check() and 0 or 1) | ||
end | ||
|
||
-- Yield in queue's on_disconnect trigger (which handles a client | ||
-- disconnection) may lead to a situation when _queue_taken | ||
-- temporary space is not cleaned and becomes inconsistent with | ||
-- 'status' field in <tube_name> space. This appears only on | ||
-- tarantool versions affected by gh-4627. | ||
-- | ||
-- See https://github.com/tarantool/queue/issues/103 | ||
-- See https://github.com/tarantool/tarantool/issues/4627 | ||
local function test_lost_session_id_after_yield() | ||
-- We must check the results of a test after | ||
-- the queue._on_consumer_disconnect trigger | ||
-- has been done. | ||
-- | ||
-- Triggers are run in LIFO order. | ||
box.session.on_disconnect(check_result) | ||
|
||
local listen = 'localhost:1918' | ||
tnt.cfg{listen = listen} | ||
|
||
local driver = 'fifottl' | ||
tube = queue.create_tube('test_tube', driver, {if_not_exists = true}) | ||
|
||
rawset(_G, 'queue', require('queue')) | ||
tube:grant('guest', {call = true}) | ||
|
||
-- We need at least two tasks to trigger box.session.id() | ||
-- call after a yield in the queue._on_consumer_disconnect | ||
-- trigger (in the version of queue before the fix). See | ||
-- more below. | ||
queue.tube.test_tube:put('1') | ||
queue.tube.test_tube:put('2') | ||
local connection = netbox.connect(listen) | ||
connection:call('queue.tube.test_tube:take') | ||
connection:call('queue.tube.test_tube:take') | ||
|
||
-- After disconnection of a client the _on_consumer_disconnect | ||
-- trigger is run. It changes 'status' field for tuples in | ||
-- <tube_name> space in a loop and removes the corresponding | ||
-- tuples from _queue_taken space. The version before the fix | ||
-- operates in this way: | ||
-- | ||
-- | <_on_consumer_disconnect> | ||
-- | for task in tasks of the client: | ||
-- | call <task:release> | ||
-- | | ||
-- | <task:release> | ||
-- | delete _queue_taken tuple using box.session.id() | ||
-- | update <tube_name> space using task_id -- !! yield | ||
-- | ||
-- So the deletion from _queue_taken may be unable to delete | ||
-- right tuples for second and following tasks, because | ||
-- box.session.id() may give a garbage. | ||
connection:close() | ||
|
||
-- Wait for check_result() trigger, which will ensure that | ||
-- _queue_taken space is cleaned and will exit successfully | ||
-- in the case (or exit abnormally otherwise). | ||
fiber.sleep(5) | ||
|
||
-- Wrong session id may lead to 'Task was not taken in the | ||
-- session' error in the _on_consumer_disconnect and so the | ||
-- second on_disconnect trigger (check_result) will not be | ||
-- fired. | ||
os.exit(1) | ||
end | ||
|
||
test_lost_session_id_after_yield() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.